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
Anonymous
Not applicable

Sum values based on category in another column/measure

I've looked at several other forums, however, none quite match my problem.

 

I want to sum all values in a row, if they match a certain category to create a new column.

 

I am starting with this table:

 

Name, Month, Value

Bob2017-1245
Bob2017-12100
Sally2017-1265
Sally2017-115
Bob2017-1110

 

But I want to create a measure or new column for each month which totals all of the values for a given person in a given month, so I want to change the table to:

 

Name, 2017-11, 2017-12

Bob10145
Sally565

 

I'm pretty new to Power BI and DAX language, so I'm having trouble getting something to work.

1 ACCEPTED SOLUTION
PattemManohar
Community Champion
Community Champion

@Anonymous  Please try "Grouping" and "Pivot" in Power Query Editor as below

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcspPUtJRMjIwNNc1NAKyTEyVYnUwhQ0NDMDiwYk5OZUoMmamWCQMgSxMgwzBBinFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Name = _t, Month = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Month", type date}, {"Value", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Name", "Month"}, {{"Value", each List.Sum([Value]), type number}}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Grouped Rows", {{"Month", type text}}, "en-GB"), List.Distinct(Table.TransformColumnTypes(#"Grouped Rows", {{"Month", type text}}, "en-GB")[Month]), "Month", "Value")
in
    #"Pivoted Column"

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




View solution in original post

2 REPLIES 2
PattemManohar
Community Champion
Community Champion

@Anonymous  Please try "Grouping" and "Pivot" in Power Query Editor as below

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcspPUtJRMjIwNNc1NAKyTEyVYnUwhQ0NDMDiwYk5OZUoMmamWCQMgSxMgwzBBinFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Name = _t, Month = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Month", type date}, {"Value", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Name", "Month"}, {{"Value", each List.Sum([Value]), type number}}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Grouped Rows", {{"Month", type text}}, "en-GB"), List.Distinct(Table.TransformColumnTypes(#"Grouped Rows", {{"Month", type text}}, "en-GB")[Month]), "Month", "Value")
in
    #"Pivoted Column"

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




@Anonymous you can also achieve this by matrix visual by

 

add name on rows

add month on columns

add value on value 

 

voila, you have the solution.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.