【问题标题】:PowerBI - Remove Initial Records with 0 valuesPowerBI - 删除具有 0 值的初始记录
【发布时间】:2017-05-20 01:30:23
【问题描述】:

我在 PowerBI 中有一个如下所示的表:

Date           StoreID       Car Sales     <Row Num (for explanation only)>
1/1/2017       1             0               1
1/2/2017       1             0               2
1/3/2017       1             0               3
1/4/2017       1             20              4 
1/5/2017       1             13              5
1/6/2017       1             0               6
1/7/2017       1             31              7

1/4/2017       2             0               8
1/5/2017       2             0               9
1/6/2017       2             7              10
1/7/2017       2             0              11
1/8/2017       2             10             12

我想要做的是创建一个按天计算汽车销售量的度量(因此在 x 轴上带有日期的折线图上),但在第一个日期之前消除带有 0 的行/记录销售价值。换句话说,我想消除第 1、2 和 3 行,但不消除第 6 行,因为那是没有售出汽车的合法日子。我也想对每个 StoreID 执行此操作,因此我想消除第 8 行和第 9 行,但不是第 11 行。有没有办法提出可以在 PowerBI 中完成此操作的度量/列(或其他方式)?

【问题讨论】:

  • 显然,我不能只创建一个显示 IF(Table1[Car Sales] = 0, BLANK(), [Car Sales]) 的列,因为这会消除之后没有销售的天数第一次销售。

标签: powerbi dax powerquery


【解决方案1】:

您可以按 StoreID 分组,然后使用以下方法转换每一列:按 [Date] 排序,然后使用 Table.Skip 删除 [Car Sales] 为 0 的行。(按 [Date] 排序似乎没有必要,但group by 可以改变顺序。)然后展开分组表。

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type datetime}, {"StoreID", Int64.Type}, {"Car Sales", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"StoreID"}, {{"Grouped", (grouped) => let
            #"Sorted Rows" = Table.Sort(grouped,{{"Date", Order.Ascending}}),
            SkipNoCarSales = Table.Skip(#"Sorted Rows", each [Car Sales] = 0)
        in
            SkipNoCarSales, type table}}),
    #"Expanded Grouped" = Table.ExpandTableColumn(#"Grouped Rows", "Grouped", {"Car Sales", "Date"}, {"Car Sales", "Date"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Expanded Grouped",{"Car Sales", "StoreID", "Date"})
in
    #"Reordered Columns"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-22
    • 2013-04-23
    • 2023-04-11
    • 2017-11-19
    • 1970-01-01
    • 2022-11-12
    • 2012-03-18
    • 1970-01-01
    相关资源
    最近更新 更多