Json使用电源查询优秀

时间:2021-07-02 17:02:03

I have some json on a website that i want to convert to excel using the power query option from web. But I ran into a small problem. My json looks like this:

我在网站上有一些json,我想使用web上的power query选项转换为excel。但我遇到了一个小问题。我的json看起来像这样:

[
    {
        "id" : 1,
        "visitors" : 26,
        "some_number" : 1,
        "value" : 3500
    },
    {
        "id" : 2,
        "visitors" : 21,
        "some_number" : 5,
        "value" : 2000
    }
]

but when i use from web i get this:

但是当我从网上使用时我得到了这个:

Json使用电源查询优秀

I can drill down into a record,convert it to a table, transpose and use first row as header but then i get just one row. How can i get all of my data to the table and not just one row?

我可以深入到一个记录,将其转换为一个表,转置并使用第一行作为标题,但后来我只得到一行。我怎样才能将所有数据都放到表中而不只是一行?

3 个解决方案

#1


8  

First I would use the List Tools / Transform menu (it should be automatically selected) and click the To Table button. This will give you a single-column table with 2 rows. Then I would click the small Expand button - it will appear in the column headings, just to the right of "Column1". Uncheck the Use original column name ... option and you will get a table of 4 columns and 2 rows.

首先,我将使用列表工具/转换菜单(应自动选择),然后单击“到表格”按钮。这将为您提供一个包含2行的单列表。然后我会点击小的展开按钮 - 它将出现在列标题中,就在“Column1”的右侧。取消选中使用原始列名...选项,您将获得一个包含4列和2行的表。

Here's the full script I generated:

这是我生成的完整脚本:

let
    Source = Json.Document(File.Contents("C:\Users\Mike.Honey\Downloads\json2.json")),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column2" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"id", "visitors", "some_number", "value"}, {"id", "visitors", "some_number", "value"})
in
    #"Expanded Column2" 

#2


3  

The Table.FromRecords() function is suitable for that sample data:

Table.FromRecords()函数适用于该示例数据:

let 
    Source = Json.Document("[{""id"": 1, ""visitors"": 26, ""some_number"": 1, ""value"": 3500}, {""id"": 2, ""visitors"": 21, ""some_number"": 5, ""value"": 2000}]"),
    AsTable = Table.FromRecords(Source)
in
    AsTable

Json使用电源查询优秀

#3


0  

You need to convert the list to a table first, then you can expand the record column and proceed from there. If no luck, then you can take a look at this video I created recently for a similar question.

您需要先将列表转换为表,然后您可以展开记录列并从那里继续。如果没有运气,那么你可以看看我最近创建的这个类似问题的视频。

#1


8  

First I would use the List Tools / Transform menu (it should be automatically selected) and click the To Table button. This will give you a single-column table with 2 rows. Then I would click the small Expand button - it will appear in the column headings, just to the right of "Column1". Uncheck the Use original column name ... option and you will get a table of 4 columns and 2 rows.

首先,我将使用列表工具/转换菜单(应自动选择),然后单击“到表格”按钮。这将为您提供一个包含2行的单列表。然后我会点击小的展开按钮 - 它将出现在列标题中,就在“Column1”的右侧。取消选中使用原始列名...选项,您将获得一个包含4列和2行的表。

Here's the full script I generated:

这是我生成的完整脚本:

let
    Source = Json.Document(File.Contents("C:\Users\Mike.Honey\Downloads\json2.json")),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column2" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"id", "visitors", "some_number", "value"}, {"id", "visitors", "some_number", "value"})
in
    #"Expanded Column2" 

#2


3  

The Table.FromRecords() function is suitable for that sample data:

Table.FromRecords()函数适用于该示例数据:

let 
    Source = Json.Document("[{""id"": 1, ""visitors"": 26, ""some_number"": 1, ""value"": 3500}, {""id"": 2, ""visitors"": 21, ""some_number"": 5, ""value"": 2000}]"),
    AsTable = Table.FromRecords(Source)
in
    AsTable

Json使用电源查询优秀

#3


0  

You need to convert the list to a table first, then you can expand the record column and proceed from there. If no luck, then you can take a look at this video I created recently for a similar question.

您需要先将列表转换为表,然后您可以展开记录列并从那里继续。如果没有运气,那么你可以看看我最近创建的这个类似问题的视频。