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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Charuhans
New Member

New Column of Row subtotals in Power Query

I am trying to create a new column which will repeat the subtotals for rows. For example:

 

DOC_IDAMOUNTSUBTOTAL
A123100450
A123300450
A12350450
A897-700-400
A897300-400
Q456200200
G253400500
G253100500

 

The new column is needed to calulate another column. It will only display the data from the "Amount" column if the "Subtotal" column is greater than "0". For example:

 

DOC IDAMOUNTSUBTOTALCALCULATED
A123100450100
A123300450300
A1235045050
A897-700-400 
A897-300-400 
Q456200200200
G523400500400
G523100500100

 

I think the CALCULATE function in DAX might do the work but I need to caluluate this in Power Query (M). The Query has more than a dozen columns, if that matters.

Any help is much appreciated! Thank you in advance.

1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @Charuhans ,

You can add a conditional column directly in Power Query Editor to achieve this:

vyingjl_0-1650332211580.png

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

2 REPLIES 2
v-yingjl
Community Support
Community Support

Hi @Charuhans ,

You can add a conditional column directly in Power Query Editor to achieve this:

vyingjl_0-1650332211580.png

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjQ0MlbSUTI0MFCK1YFzjVG5plCehaU5kKdrboDChykONDE1A3KNoFx3U7BeE1Qu2KJYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"DOC ID" = _t, AMOUNT = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"AMOUNT", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"DOC ID"}, {{"subtot", each List.Sum([AMOUNT]), type nullable number}, {"amt", each _}}),
    #"Expanded amt" = Table.ExpandTableColumn(#"Grouped Rows", "amt", {"AMOUNT"}, {"AMOUNT"}),
    #"Added Custom" = Table.AddColumn(#"Expanded amt", "amntot", each if [subtot]>0 then [AMOUNT] else "")
in
    #"Added Custom"

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.