Forum Discussion
Troyvan
4 years agoHelper I
Adding columns subtotal
Hi All, Apologies if this has been answered previously. I'm trying to creat a column showing total per quarter but I can't seem to add selected column totals here. My data looks like this: ...
- 4 years ago
See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again)
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXLOyUzNKwGxQooSy1JzgAxTA4KEoQFuMlYnWskIbjKIFVyalJyfV1KUmFySX1RMQDsqaYaHBFlkDLfImDKLjPCQIItM4BaZwMNKIabUwMDITMExOTk/Nzc/JbEkMz8PZCIkjIggjXRMDQjTIPtN4fabYvWoqY4BxDfkMfDFZywA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Job No" = _t, Client = _t, Ledger = _t, #"Jan-22" = _t, #"Feb-22" = _t, #"Mar-22" = _t, #"Apr-22" = _t, #"May-22" = _t, #"Jun-22" = _t, #"Jul-22" = _t, #"Aug-22" = _t, #"Sep-22" = _t, #"Oct-22" = _t, #"Nov-22" = _t, #"Dec-22" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Job No", Int64.Type}, {"Client", type text}, {"Ledger", type text}, {"Jan-22", Int64.Type}, {"Feb-22", Int64.Type}, {"Mar-22", Int64.Type}, {"Apr-22", Int64.Type}, {"May-22", Int64.Type}, {"Jun-22", Int64.Type}, {"Jul-22", Int64.Type}, {"Aug-22", Int64.Type}, {"Sep-22", Int64.Type}, {"Oct-22", Int64.Type}, {"Nov-22", Int64.Type}, {"Dec-22", Int64.Type}}), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Ledger", "Client", "Job No"}, "Attribute", "Value"), #"Changed Type1" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Attribute", type date}}), #"Added Custom" = Table.AddColumn(#"Changed Type1", "Quarter", each "Q"&Text.From(Number.RoundUp(Date.Month([Attribute])/3,0))), #"Grouped Rows" = Table.Group(#"Added Custom", {"Quarter"}, {{"Total", each List.Sum([Value]), type number}}) in #"Grouped Rows"
Troyvan
4 years agoHelper I
It worked! Thank you so much Vijay 🙂
Cheers,
Troy