【问题标题】:Power BI case insensitive with JSONPower BI 对 JSON 不区分大小写
【发布时间】:2018-02-15 12:17:56
【问题描述】:

我通过 resources.azure.com 上的 API 连接到 Azure 资源,从那里获取 Microsoft.Compute 的 API,并通过 JSON 将所有 VM 详细信息导入 Power BI。

导入工作正常,但是在某些数据情况下存在大小写差异。例如,在使用标签值时,有些人输入了相同的单词但大小写不同,例如;

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

相比

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

在 Power BI 中展开列时,它会将上面列出的项目视为两个不同的值。

理想情况下,我希望导入 JSON 并忽略“大小写”,或者将所有传入的内容标记为大写或小写。

我已阅读下面的两个链接,但我是 Power BI 的新手,我不确定如何实现它,或者即使它是我需要的。

Case sensitivity in Power BIPower BI changing text case automaticallyhttp://www.thebiccountant.com/2016/10/27/tame-case-sensitivity-power-query-powerbi/

这是我的高级编辑器代码:

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"

如果您想知道为什么我的查询要导入这么长,请在此处查看我之前的帖子:Power BI - Call Azure API with nextLink (next page)

任何帮助将不胜感激。

【问题讨论】:

    标签: json azure powerbi


    【解决方案1】:

    我今天也在为同样的问题而苦苦挣扎。一种解决方法虽然不优雅,但将上游的 JSON 小写或大写。

    作为临时解决方案为我工作。

    希望对你有帮助, 克里斯

    【讨论】:

    • @Chris W,这让我很头疼。如果你能找到另一个解决方法,那么我会全力以赴。遗憾的是,当传入的 JSON 直接来自 Azure API 时,我找不到更改它的方法,但我会记住这一点,看看是否可行。
    【解决方案2】:

    您的问题似乎直接来自数据源以及数据源级别的字段名称之间的差异。

    这是一个示例代码,说明如何强制/确保它们都具有相同的大小写:

    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)})))
    

    【讨论】:

    • 我已经在我现有的代码中实现了这一点,但遗憾的是,我虚弱的大脑无法解决它:-/
    【解决方案3】:

    我已经在另一个论坛上回答过这个问题并尝试过,它确实有效。

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

    “您可以在展开之前(在最后一步)重命名记录字段(例如通过应用 Text.Proper):”

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

    最终输出如下所示:

    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"
    

    希望这对其他人有所帮助!

    【讨论】:

      猜你喜欢
      • 2022-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-15
      • 2012-12-01
      • 2013-03-06
      • 2020-02-18
      相关资源
      最近更新 更多