简体   繁体   English

Power BI大小写与JSON不相关

[英]Power BI case insensitive with JSON

I'm connecting to Azure resources via API at resources.azure.com, from there I'm taking the API for Microsoft.Compute and importing all the VM details into Power BI via JSON. 我正在通过resources.azure.com上的API通过Azure连接到Azure资源,从那里获取Microsoft的API。计算并通过JSON将所有VM详细信息导入Power BI。

The import works fine, however with some situations of the data there is case discrepancy. 导入工作正常,但是在某些情况下数据存在大小写差异。 For example, when working with the tags value, some people have typed the same word but in different case, such as; 例如,当使用标签值时,有些人键入了相同的单词,但大小写不同,例如;

    "tags": {
      "Project": "DT",
      "SLStandard": "Yes"

compared to 相比

    "tags": {
      "project": "DT",
      "SlStandard": "Yes"

When expanding the columns out in Power BI it will consider the items listed above as two different value. 在Power BI中扩展列时,它将上面列出的项目视为两个不同的值。

Power BI区分大小写

Ideally I would like to have the JSON imported and the 'case' ignored, or perhaps mark all incoming as either upper or lower case. 理想情况下,我希望导入JSON并忽略“大小写”,或者将所有传入标记为大写或小写。

I have read the two links below, but I'm new to Power BI and I'm unsure how to implement it, or even if it is what I need. 我已经阅读了下面的两个链接,但是我是Power BI的新手,我不确定如何实现它,即使我需要它也不知道。

Case sensitivity in Power BI and Power BI changing text case automatically and http://www.thebiccountant.com/2016/10/27/tame-case-sensitivity-power-query-powerbi/ Power BIPower BI中的区分大小写会自动更改文本大小写,并且http://www.thebiccountant.com/2016/10/27/tame-case-sensitiveivity-power-query-powerbi/

Here is my Advanced Editor code: 这是我的高级编辑器代码:

let
    iterations = 10,
    url = 
     "https://management.azure.com/subscriptions/< subscription id >/providers/Microsoft.Compute/virtualMachines?api-version=2017-12-01",

    FnGetOnePage =
     (url) as record =>
      let
       Source = Json.Document(Web.Contents(url)),
       data = try Source[value] otherwise null,
       next = try Source[nextLink] otherwise null,
       res = [Data=data, Next=next]
      in
       res,

    GeneratedList =
     List.Generate(
      ()=>[i=0, res = FnGetOnePage(url)],
      each [i]<iterations and [res][Data]<>null,
      each [i=[i]+1, res = FnGetOnePage([res][Next])],
      each [res][Data]),
    #"Converted to Table" = Table.FromList(GeneratedList, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandListColumn(#"Converted to Table", "Column1"),
    #"Expanded Column2" = Table.ExpandRecordColumn(#"Expanded Column1", "Column1", {"tags"}, {"Column1.tags"}),
    #"Expanded Column1.tags" = Table.ExpandRecordColumn(#"Expanded Column2", "Column1.tags", {"Project", "project", "SLStandard", "sLStandard", "BIOffline", "bIStandard", "AutomationBI", "biStandard", "BIStandard", "asdf-U001", "TestVM"}, {"Column1.tags.Project.1", "Column1.tags.project", "Column1.tags.SLStandard.1", "Column1.tags.sLStandard", "Column1.tags.BIOffline", "Column1.tags.bIStandard.1", "Column1.tags.AutomationBI", "Column1.tags.biStandard.2", "Column1.tags.BIStandard", "Column1.tags.asdf-U001", "Column1.tags.TestVM"})
in
    #"Expanded Column1.tags"

If you're wondering about why my query is so long for import, then check out my previous post here: Power BI - Call Azure API with nextLink (next page) 如果您想知道为什么我的查询需要这么长的时间,请在此处查看我的上一篇文章: Power BI-使用nextLink调用Azure API(下一页)

Any help would be greatly appreciated. 任何帮助将不胜感激。

I'm struggling with the same issue today. 我今天在同一个问题上挣扎。 One workaround, although not elegant, is to lowercase or UPPERCASE the JSON upstream. 一种解决方法(虽然不够优雅)是在上游小写或大写JSON。

Worked for me as a temporary solution. 为我工作,是一个临时解决方案。

Hope it helps, Chris 希望能帮上忙,克里斯

It seems that your issue is coming directly from the data source and the discrepancy between the field names at the data source level. 看来您的问题直接来自数据源,而数据源级别的字段名称之间存在差异。

Here's a sample code on how you can force/make sure that they all have the same casing: 这是有关如何强制/确保它们都具有相同大小写的示例代码:

let
  Source = {[A=24,b=53], [a=43,B=43], [a=3,b=3]},
  Custom1 = List.Transform(Source, (_)=> Record.RenameFields(_, List.Zip({Record.FieldNames(_), List.Transform(Record.FieldNames(_), Text.Lower)})))

I've had this answered on another forum and tried it, and it does work. 我已经在另一个论坛上回答了这个问题并进行了尝试,它确实起作用。

https://community.powerbi.com/t5/Desktop/Power-BI-case-insensitive-with-JSON/mp/360134 https://community.powerbi.com/t5/Desktop/Power-BI-case-insensitive-with-JSON/mp/360134

"You can rename your record fields (by applying Text.Proper for example) before expanding (in the last step):" “在展开(在最后一步中)之前,您可以重命名记录字段(例如,通过应用Text.Proper):”

Table.TransformColumns(#"Expanded Column2", {{"tags", each Record.RenameFields(_, List.Zip({Record.FieldNames(_), List.Transform(Record.FieldNames(_), (name)=> Text.Proper(name))}))}}),

An the final output looks like this: 最终输出如下所示:

let
    iterations = 10,
    url = 
     "https://management.azure.com/subscriptions/< subscription >/providers/Microsoft.Compute/virtualMachines?api-version=2017-12-01",

FnGetOnePage =
 (url) as record =>
  let
   Source = Json.Document(Web.Contents(url)),
   data = try Source[value] otherwise null,
   next = try Source[nextLink] otherwise null,
   res = [Data=data, Next=next]
  in
   res,

GeneratedList =
 List.Generate(
  ()=>[i=0, res = FnGetOnePage(url)],
  each [i]<iterations and [res][Data]<>null,
  each [i=[i]+1, res = FnGetOnePage([res][Next])],
  each [res][Data]),
#"Converted to Table" = Table.FromList(GeneratedList, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandListColumn(#"Converted to Table", "Column1"),
#"Expanded Column2" = Table.ExpandRecordColumn(#"Expanded Column1", "Column1", {"properties", "tags"}, {"properties", "tags"}),
#"Expanded properties" = Table.TransformColumns(#"Expanded Column2", {{"tags", each Record.RenameFields(_, List.Zip({Record.FieldNames(_), List.Transform(Record.FieldNames(_), (name)=> Text.Proper(name))}))}}),
#"Expanded properties1" = Table.ExpandRecordColumn(#"Expanded properties", "properties", {"vmId"}, {"properties.vmId"}),
#"Expanded tags" = Table.ExpandRecordColumn(#"Expanded properties1", "tags", {"Project", "Slstandard", "Bioffline", "Bistandard", "Automationbi", "asdf-U001", "Testvm"}, {"tags.Project", "tags.Slstandard", "tags.Bioffline", "tags.Bistandard", "tags.Automationbi", "tags.asdf-U001", "tags.Testvm"})
in
#"Expanded tags"

Hope this helps other people! 希望这对其他人有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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