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

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

Reply
Anonymous
Not applicable

Sum data to new rows in same table

Hi all,

 

Would appreciate some guidance on an challenge I have. Basically I'm working with some sales data that shows global countries, but for the US shows each State split out with no Total US row. My data looks something like the below without the rows in red.

What I would like to do is append to the same table rows that represent total US per product. I have a dozen or so columns with values that each need to be summed (I've just included 3 below for illustration). Basically I want to generate the rows in red.

 

I'd rather not split the data into another table, as I have data in this format in multiple tables already for different years.

 

MarketProductSales ValueSales VolumeCOGS
ItalyX109(3)
MichiganY57(1)
New JerseyZ144(5)
OhioY56(6)
SpainZ1510(7)
TexasZ85(4)
USY1013(7)
USZ229(9)

 

Any help is appreciated!

1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi lavelle72, 

You could refer to my sample for details(create a table for reference).

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8ixJzKlU0lGKAGJDAyBhCcQaxppKsTrRSr6ZyRmZ6Yl5QKFIIDYFYnOQtCFE2i+1XMErtag4FWRAFMgAEyABwhqmEBX+GZn5SJrNQFJmEKnggsTMPJg+U5jtGuYQ2ZDUisRiqKwFVLeGCVAuFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Market = _t, Product = _t, #"Sales Value" = _t, #"Sales Volume" = _t, COGS = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Market", type text}, {"Product", type text}, {"Sales Value", Int64.Type}, {"Sales Volume", Int64.Type}, {"COGS", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Market"}, #"Table (2)", {"Market"}, "Table (2)", JoinKind.LeftOuter),
    #"Expanded Table (2)" = Table.ExpandTableColumn(#"Merged Queries", "Table (2)", {"country"}, {"Table (2).country"}),
    #"Grouped Rows" = Table.Group(#"Expanded Table (2)", {"Table (2).country", "Product"}, {{"Sales Value", each List.Sum([Sales Value]), type number}, {"Sales Volume", each List.Sum([Sales Volume]), type number}, {"COGS", each List.Sum([COGS]), type number}, {"Market", each List.Min([#"Table (2).country"]), type text}}),
    #"Filtered Rows1" = Table.SelectRows(#"Grouped Rows", each ([#"Table (2).country"] = "US")),
    #"Appended Query" = Table.Combine({#"Filtered Rows1", #"Expanded Table (2)"}),
    #"Removed Columns" = Table.RemoveColumns(#"Appended Query",{"Table (2).country"})
in
    #"Removed Columns"

Best Regards,
Zoe Zhi

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

5 REPLIES 5
dax
Community Support
Community Support

Hi lavelle72, 

You could refer to my sample for details(create a table for reference).

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8ixJzKlU0lGKAGJDAyBhCcQaxppKsTrRSr6ZyRmZ6Yl5QKFIIDYFYnOQtCFE2i+1XMErtag4FWRAFMgAEyABwhqmEBX+GZn5SJrNQFJmEKnggsTMPJg+U5jtGuYQ2ZDUisRiqKwFVLeGCVAuFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Market = _t, Product = _t, #"Sales Value" = _t, #"Sales Volume" = _t, COGS = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Market", type text}, {"Product", type text}, {"Sales Value", Int64.Type}, {"Sales Volume", Int64.Type}, {"COGS", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Market"}, #"Table (2)", {"Market"}, "Table (2)", JoinKind.LeftOuter),
    #"Expanded Table (2)" = Table.ExpandTableColumn(#"Merged Queries", "Table (2)", {"country"}, {"Table (2).country"}),
    #"Grouped Rows" = Table.Group(#"Expanded Table (2)", {"Table (2).country", "Product"}, {{"Sales Value", each List.Sum([Sales Value]), type number}, {"Sales Volume", each List.Sum([Sales Volume]), type number}, {"COGS", each List.Sum([COGS]), type number}, {"Market", each List.Min([#"Table (2).country"]), type text}}),
    #"Filtered Rows1" = Table.SelectRows(#"Grouped Rows", each ([#"Table (2).country"] = "US")),
    #"Appended Query" = Table.Combine({#"Filtered Rows1", #"Expanded Table (2)"}),
    #"Removed Columns" = Table.RemoveColumns(#"Appended Query",{"Table (2).country"})
in
    #"Removed Columns"

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

amitchandak
Super User
Super User

You can one additional column that can mark it US Data of not, let say US Flag. You can have a new column like

 

new country = if([us flag] ="Y", "US", [country]), You can use this one for display.

 

You can also explore Union and summarize option

https://docs.microsoft.com/en-us/dax/union-function-dax

https://docs.microsoft.com/en-us/dax/summarize-function-dax

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks.
My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p...
https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thanks for the suggestion Amit.

The flag idea seemed the simplest so I have been playing around with that, per your suggestion. 

 

The issue I face now is that for each product, I see multiple rows for New Country = US (makes sense as each row previously was a State). Now when I use New Country for display, all metrics get summed together - this is fine for some, but not for others which should be weighted averages.

I am going to have a closer look at the SUMMARIZE and UNION option to see if that will work better.

dax
Community Support
Community Support

Hi lavelle72, 

Did you try the M code? Will this works or not? By the way, you also could inform me some of your sample data, then I will help you more correctly.

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

AnkitBI
Solution Sage
Solution Sage

Hi @Anonymous 

Can you share your sample data. Primarily what you can do.

1) In Power Query, use Group By to summarise data at country level for US and then append with your base table OR

2) In DAX, create a new table using SUMMARIZE function to summarise data at country level for US and then use UNION to append with your base table

 

Thanks
Ankit Jain
Do Mark it as solution if the response resolved your problem. Do Kudo the response if it seems good and helpful.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.