在 Power BI 中获取 JSON 个形状地图视觉对象的 table 个地图键
Get table of map keys of JSON shape map visual in Power BI
有没有简单的方法来获取地图形状视觉对象的 table 地图键?我想将地图键作为 Power Query 的 table。最好的方法是从导入地图的 JSON 文件中提取它。
下载文件:NZ.json
在查询编辑器中向下钻取对象和几何图形,转换为 table,然后展开 properties
列:
let
Source = Json.Document(File.Contents("C:\Users\aolson\Downloads\NZ.json")),
objects = Source[objects],
gadm36_NZL_1 = objects[gadm36_NZL_1],
geometries = gadm36_NZL_1[geometries],
ConvertToTable = Table.FromList(geometries, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
ExpandColumn = Table.ExpandRecordColumn(ConvertToTable, "Column1", {"properties"}, {"properties"}),
ExpandProperties = Table.ExpandRecordColumn(ExpandColumn, "properties", {"GID_0", "NAME_0", "GID_1", "NAME_1", "VARNAME_1", "NL_NAME_1", "TYPE_1", "ENGTYPE_1", "CC_1", "HASC_1"}, {"GID_0", "NAME_0", "GID_1", "NAME_1", "VARNAME_1", "NL_NAME_1", "TYPE_1", "ENGTYPE_1", "CC_1", "HASC_1"})
in
ExpandProperties
如果您想让它更动态一点,请将单个 ExpandProperties
公式行替换为以下两个:
ColumnNames = Record.FieldNames(ExpandColumn[properties]{0}),
ExpandProperties = Table.ExpandRecordColumn(ExpandColumn, "properties", ColumnNames, ColumnNames)
扩展亚历克西斯接受的答案,我想变得更加动态。文件的路径是唯一的变量。
let
Source = Json.Document(File.Contents("C:\NZ.json")),
#"Converted to Table" = Record.ToTable(Source),
Value1 = #"Converted to Table"{3}[Value],
#"Converted to Table1" = Record.ToTable(Value1),
Value2 = #"Converted to Table1"{0}[Value],
geometries = Value2[geometries],
#"Converted to Table2" = Table.FromList(geometries, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table2", "Column1", {"arcs", "type", "properties"}, {"arcs", "type", "properties"}),
#"Removed Other Columns" = Table.SelectColumns(#"Expanded Column1",{"properties"}),
ColumnNames = Record.FieldNames(#"Removed Other Columns"[properties]{0}),
ExpandProperties = Table.ExpandRecordColumn(#"Removed Other Columns", "properties", ColumnNames, ColumnNames)
in
ExpandProperties
有没有简单的方法来获取地图形状视觉对象的 table 地图键?我想将地图键作为 Power Query 的 table。最好的方法是从导入地图的 JSON 文件中提取它。
下载文件:NZ.json
在查询编辑器中向下钻取对象和几何图形,转换为 table,然后展开 properties
列:
let
Source = Json.Document(File.Contents("C:\Users\aolson\Downloads\NZ.json")),
objects = Source[objects],
gadm36_NZL_1 = objects[gadm36_NZL_1],
geometries = gadm36_NZL_1[geometries],
ConvertToTable = Table.FromList(geometries, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
ExpandColumn = Table.ExpandRecordColumn(ConvertToTable, "Column1", {"properties"}, {"properties"}),
ExpandProperties = Table.ExpandRecordColumn(ExpandColumn, "properties", {"GID_0", "NAME_0", "GID_1", "NAME_1", "VARNAME_1", "NL_NAME_1", "TYPE_1", "ENGTYPE_1", "CC_1", "HASC_1"}, {"GID_0", "NAME_0", "GID_1", "NAME_1", "VARNAME_1", "NL_NAME_1", "TYPE_1", "ENGTYPE_1", "CC_1", "HASC_1"})
in
ExpandProperties
如果您想让它更动态一点,请将单个 ExpandProperties
公式行替换为以下两个:
ColumnNames = Record.FieldNames(ExpandColumn[properties]{0}),
ExpandProperties = Table.ExpandRecordColumn(ExpandColumn, "properties", ColumnNames, ColumnNames)
扩展亚历克西斯接受的答案,我想变得更加动态。文件的路径是唯一的变量。
let
Source = Json.Document(File.Contents("C:\NZ.json")),
#"Converted to Table" = Record.ToTable(Source),
Value1 = #"Converted to Table"{3}[Value],
#"Converted to Table1" = Record.ToTable(Value1),
Value2 = #"Converted to Table1"{0}[Value],
geometries = Value2[geometries],
#"Converted to Table2" = Table.FromList(geometries, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table2", "Column1", {"arcs", "type", "properties"}, {"arcs", "type", "properties"}),
#"Removed Other Columns" = Table.SelectColumns(#"Expanded Column1",{"properties"}),
ColumnNames = Record.FieldNames(#"Removed Other Columns"[properties]{0}),
ExpandProperties = Table.ExpandRecordColumn(#"Removed Other Columns", "properties", ColumnNames, ColumnNames)
in
ExpandProperties