首页 > 解决方案 > Power BI 在列上使用 $expand

问题描述

Power BI新手在这里。

我想根据我的 Azure DevOps 数据(https://docs.microsoft.com/en-us/azure/devops/report/powerbi/sample-test-plans-execution )构建 Power BI 可视化,如示例报告中所示-trend?view=azure-devops&tabs=powerbi)。

使用 DateSK 制作 X 轴似乎不起作用,因为 PowerBI 将其视为一个整数,并且我的可视化中 X 轴的方式是线性的(绘制的 X 轴如下所示:20200100 20200150 20200200 20200250 等等)。我想查看 Microsoft 文档中显示的每日视图。

PowerBI 也不允许我将 DateSK 数据类型从整数转换为日期格式。

我曾尝试$expand在我的 Power BI 查询中使用,但似乎日期列无法让我扩展或者我做错了。

如果您有任何解决方法或使用$expand. 我想查看扩展的日期格式而不是 DateSK。

下面是来自微软文档的参考,如上面的链接所示:

let 
    Source = OData.Feed ("https://analytics.dev.azure.com/{organization}/{project}/_odata/v3.0-preview/TestPointHistorySnapshot?" 
        &"$apply=filter((TestSuite/TestPlanTitle eq '{testPlanTitle}') and (DateSK ge {startDate} and DateSK le {endDate}))" 
        &"/groupby(" 
            &"(DateSK)," 
            &"aggregate(" 
                &"$count as TotalCount," 
                &"cast(ResultOutcome  eq 'Passed', Edm.Int32) with sum as Passed," 
                &"cast(ResultOutcome  eq 'Failed', Edm.Int32) with sum as Failed," 
                &"cast(ResultOutcome eq 'Blocked', Edm.Int32) with sum as Blocked," 
                &"cast(ResultOutcome eq 'NotApplicable', Edm.Int32) with sum as NotApplicable," 
                &"cast(ResultOutcome eq 'None', Edm.Int32) with sum as NotExecuted," 
                &"cast(ResultOutcome ne 'None', Edm.Int32) with sum as Executed 
            ) 
        )", null, [Implementation="2.0"]) 
in 
    Source

标签: powerbiodata

解决方案


我通过将列转换两次来实现这一点,首先是文本,然后是日期。

下面我展示了高级编辑器中的查询更改,但我在可视查询编辑器中进行了列转换。我在第一步将计数转换为整数,并将 dateSK 转换为文本。

在第二步中,我将 Date 列转换为日期,然后将该列从 DateSK 重命名为 Date。

    #"Changed Type" = Table.TransformColumnTypes(Source,{{"TotalCount", Int64.Type}, {"Passed", Int64.Type}, {"Failed", Int64.Type}, {"Blocked", Int64.Type}, {"NotApplicable", Int64.Type}, {"NotExecuted", Int64.Type}, {"Executed", Int64.Type}, {"DateSK", type text}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Changed Type",{{"DateSK", type date}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"DateSK", "Date"}}),

推荐阅读