简体   繁体   中英

Smartsheet data in Excel via Power Query

The API output from Smartsheet returns rows and columns as separate objects,that are independent of each other. This results in separate records for the columns(A list of field names) and another set of records for the rows(records with a single field of values from various fields)

Is there a way to return a single list of JSON (with rows and columns resulting in a single list of records)?

This is the code I'm using in the Query Editor that returns separate Rows and Columns

= Web.Contents(
    "https://api.smartsheet.com/1.1/sheet/[SHEET_ID]",
    [
        Headers = 
        [
            #"Authorization" = "Bearer YOUR_API_TOKEN"
        ]
    ]
)

I used the sample data on their site to come up with this set of transformations:

let
    Source = Json.Document(File.Contents("D:\testdata\foo.json")),
    ColumnIds = List.Transform(Source[columns], each Text.From([id])),
    ColumnNames = List.Transform(Source[columns], each [title]),
    Table = Table.FromList(Source[rows], Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    Expanded = Table.ExpandRecordColumn(Table, "Column1", {"rowNumber", "cells"}, {"rowNumber", "cells"}),
    Mapped = Table.TransformColumns(Expanded, {"cells",
        each Record.Combine(List.Transform(_, each Record.AddField([], Text.From([columnId]), [value])))}),
    Result = Table.ExpandRecordColumn(Mapped, "cells", ColumnIds, ColumnNames)
in
    Result

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM