汇总 table 销售额

Summarizing table sales

我有订单table喜欢

CustomerId  OrderAmount Orderdatetime   OrderAmountCurrency
AAA 120 02/03/2022 02:03    US0
AAA 20  02/03/2022 02:20    US
AAA 320 03/03/2022 03:03    US0
BBB 300 02/03/2022 02:03    0
BBB 20  02/03/2022 02:20    
BBB 200 02/03/2022 03:03    0

我想这样显示 table:Customerid, initial order-the first attempt amount All purchases world less than $40 should be excluded, Ordedate-the order of the first attempt ; Final Order- 最后的尝试

CustomerId  InitialOrder    Orderdate   FinalOrder
AAA US0  02/03/2022 02:03    US0
BBB 0    02/03/2022 02:03    0

怎么做?

在power query中,需要根据Custom ID进行分组,自定义代码如下

let  Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Orderdatetime", type datetime}, {"OrderAmount", type number}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"CustomerId"}, {
    {"Initial Order", each Table.Sort(_,{{"Orderdatetime", Order.Ascending}}){0}[OrderAmount]},
    {"Initial Order Date", each Table.Sort(_,{{"Orderdatetime", Order.Ascending}}){0}[Orderdatetime]},
    {"Last Order", each Table.LastN(Table.Sort(_,{{"Orderdatetime", Order.Ascending}}),1){0}[OrderAmount]}
    }),
#"Changed Type1" = Table.TransformColumnTypes(#"Grouped Rows",{{"Initial Order Date", type datetime}, {"Last Order", type number}, {"Initial Order", type number}})
in  #"Changed Type1"