【发布时间】:2021-10-01 07:23:52
【问题描述】:
我一直在尝试使用 Power BI / Power Query / M 代码转换 JSON 文件。
我想将我的示例 JSON 数据(如下提供)解析为如下表格格式:
到目前为止我的 Power BI / Power Query / M 代码
let
Source = Json.Document(File.Contents("C:\demo.json")),
#"Converted to Table" = Record.ToTable(Source),
#"Expanded Value" = Table.ExpandListColumn(#"Converted to Table", "Value"),
#"Expanded Value1" = Table.ExpandRecordColumn(#"Expanded Value", "Value", {"ReportID", "ReportName", "ReportType", "ReportTitles", "ReportDate", "UpdatedDateUTC", "Rows"}, {"ReportID", "ReportName", "ReportType", "ReportTitles", "ReportDate", "UpdatedDateUTC", "Rows"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Value1",{"Name", "ReportID", "ReportName", "ReportType", "ReportTitles", "ReportDate", "UpdatedDateUTC"}),
#"Expanded Rows" = Table.ExpandListColumn(#"Removed Columns", "Rows"),
#"Expanded Rows1" = Table.ExpandRecordColumn(#"Expanded Rows", "Rows", {"RowType", "Cells", "Title", "Rows"}, {"RowType", "Cells", "Title", "Rows.1"})
in
#"Expanded Rows1"
我的代码达到了这样一个点:查询结果有一行用于标题内容,一行用于两个部分的内容。
我被困在如何将 JSON 数组列表扩展为列而不是行?具体来说:
-
List在Header行Cells列 -
List在两个Section行Rows.1列中
任何提示、提示、想法、指针?
示例 JSON 文件
{
"Reports": [
{
"ReportID": "ProfitAndLoss",
"ReportName": "Profit and Loss",
"ReportType": "ProfitAndLoss",
"ReportTitles": [
"Profit & Loss",
"Demo Company (AU)",
"1 February 2018 to 28 February 2018"
],
"ReportDate": "25 February 2018",
"UpdatedDateUTC": "\/Date(1519593468971)\/",
"Rows": [
{
"RowType": "Header",
"Cells": [
{ "Value": "" },
{ "Value": "28 Feb 18" },
{ "Value": "28 Jan 18" }
]
},
{
"RowType": "Section",
"Title": " Income",
"Rows": [
{
"RowType": "Row",
"Cells": [
{
"Value": "Sales",
"Attributes": [
{
"Value": "e2bacdc6-2006-43c2-a5da-3c0e5f43b452",
"Id": "account"
}
]
},{
"Value": "9220.05",
"Attributes": [
{
"Value": "e2bacdc6-2006-43c2-a5da-3c0e5f43b452",
"Id": "account"
}
]
},{
"Value": "5120.05",
"Attributes": [
{
"Value": "e2bacdc6-2006-43c2-a5da-3c0e5f43b452",
"Id": "account"
}
]
}
]
},
{
"RowType": "SummaryRow",
"Cells": [
{ "Value": "Total Income" },
{ "Value": "9220.05" },
{ "Value": "1250.09" }
]
}
]
},{
"RowType": "Section",
"Rows": [
{
"RowType": "Row",
"Cells": [
{ "Value": "NET PROFIT" },
{ "Value": "-6250.09" },
{ "Value": "-7250.09" }
]
}
]
}
]
}
]
}
【问题讨论】:
标签: json powerbi powerquery