Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Troyvan
Helper I
Helper 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: 

Job NoClientLedgerJan-22Feb-22Mar-22Apr-22May-22Jun-22Jul-22Aug-22Sep-22Oct-22Nov-22Dec-22
1Client1Travel 50505050505050100100100100100
2Client2Subcontractors100100100100100100100600600600600600
3Client3Subcontractors100100100100100100100200200200200200
4Client4Travel & Accommodation 1501501501501501501502,5002,5002,5002,5002,500
5Client5Subcontractors15,00015,00015,00015,00015,00015,00015,000100100100100100
Total  15,40015,40015,40015,40015,40015,40015,4003,5003,5003,5003,5003,500

 

How can I simply add total of every 3 months to create quarterly totals? Thanks! 

 

Cheers,
Troy

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

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"

 

View solution in original post

2 REPLIES 2
Troyvan
Helper I
Helper I

It worked! Thank you so much Vijay 🙂

 

Cheers,
Troy

Vijay_A_Verma
Super User
Super User

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"

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors