PowerQuery COUNTIF Previous Dates

前端 未结 1 1362
日久生厌
日久生厌 2021-01-28 03:40

I\'m a little rusty on PowerQuery.
I need to count \"previous\" entries in the same table.

For example, let\'s say we have a table of car sales.
For the purposes

相关标签:
1条回答
  • 2021-01-28 04:15

    You can do this sort of thing using List and Table functions. I'll show both.

    let
        Source = Excel.CurrentWorkbook(){[Name="tblCarSales"]}[Content],
        #"Added Custom" = Table.AddColumn(Source, "Previous Sale Count",
                             (C) => List.Count(List.Select(Source[Sale Date],
                                    each _ < C[Sale Date]))),
        #"Added Custom1" = Table.AddColumn(#"Added Custom", "Previous Sale Count By Make",
                             (C) => Table.RowCount(Table.SelectRows(Source,
                                    (S) => S[Sale Date] < C[Sale Date] and S[Make] = C[Make])))
    in
        #"Added Custom1"
    

    We have to use the functions so that Power Query knows what context we're looking at the columns in. For further reading, check out this Power Query M Primer.

    0 讨论(0)
提交回复
热议问题