PowerBI - 删除具有 0 值的初始记录

PowerBI - Remove Initial Records with 0 values

我在 PowerBI 中有一个 table,如下所示:

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 消除 rows/records 直到第一个具有销售价值的日期。换句话说,我想删除第 1、2 和 3 行,但不删除第 6 行,因为那是没有汽车售出的合法日期。我还想为每个 StoreID 执行此操作,因此我想删除第 8 行和第 9 行,但不删除第 11 行。有没有办法想出一个 measure/column(或其他方法)来在 PowerBI 中完成此操作?

您可以按 StoreID 分组,然后通过以下方式转换每一列:按 [Date] 排序,然后使用 Table.Skip 删除 [Car Sales] 为 0 的行。(按 [Date] 排序可能不会似乎有必要,但分组依据可以更改顺序。)然后展开分组表。

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"