Forum Discussion
Help with List generate
- Anonymous2 years ago
Hi Hannisky
You can put the following code to advanced editor in power query
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hZJBDoAgDAT/wtmElkIsbyH8/xsaIaTKNiYerDvCZKG1kChJ5BSFw/EemEI/IMBR6Bl24H7Efl6oGbIL0FikAOAr9Ppv2RmAgLG4wFwhuwBSs0AdOzDIP2YVmIuXg8rqT2M2B1Y21r03heeoP10pKLt4Oe33S/cmgZR99+xOV24q9Qs=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Dt1 = _t, Dt2 = _t, Amt1 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Dt1", type date}, {"Dt2", type date}, {"Amt1", Int64.Type}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Amt2", each let _select=Table.SelectRows(#"Changed Type",(x)=>x[Dt1]<=[Dt1] and (x[Dt2]>x[Dt1] or x[Dt2]=null)) in List.Sum(_select[Amt1])) in #"Added Custom"Output
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Hannisky
You can put the following code to advanced editor in power query
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hZJBDoAgDAT/wtmElkIsbyH8/xsaIaTKNiYerDvCZKG1kChJ5BSFw/EemEI/IMBR6Bl24H7Efl6oGbIL0FikAOAr9Ppv2RmAgLG4wFwhuwBSs0AdOzDIP2YVmIuXg8rqT2M2B1Y21r03heeoP10pKLt4Oe33S/cmgZR99+xOV24q9Qs=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Dt1 = _t, Dt2 = _t, Amt1 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Dt1", type date}, {"Dt2", type date}, {"Amt1", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Amt2", each let
_select=Table.SelectRows(#"Changed Type",(x)=>x[Dt1]<=[Dt1] and (x[Dt2]>x[Dt1] or x[Dt2]=null))
in List.Sum(_select[Amt1]))
in
#"Added Custom"
Output
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, yes thank you so much 🙏 This was exactly what I needed. I owe you a cup of hot cocoa or something 😊
One thing I did change the inner loop (x) to check against the outer record [Dt1] instead of itself x[Dt1], in case anyone reuses the code. Both work but give slightly different results.
Changed this:
and (x[Dt2]>x[Dt1] or x[Dt2]=null))to this...
and (x[Dt2]>[Dt1] or x[Dt2]=null))...worked like a charm.