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 that contain identical row values based on values in another column

Hello power bi community! Long time reader, first time caller.

 

I am hoping it's possible to construct a measure that can sum values that don't (or do) contain certain values in another column, where a column contains identical values (in this case the transaction number). For example, i have the following data:

 

StoreTransaction noproduct typesales $
1123merch700
1123warranty150
1123install150
1123merch500
2124merch600
3125merch450
2126merch600

 

and then i use a matrix to sum that data like so:

 

StoreTransaction nosum of sales $
11231500
2124600
2126600
3125450

 

What I’m hoping to get is a measure i can put in the matrix, similar to the following, where i can sum the data that contains merch and a service (IE: warranty or install), where the transaction number is the same ("service sales"), and also that perhaps may not have any services attached ("merch only sales"). In my case, sometimes merch will be sold on its own, and sometimes with either a warranty or an install, or both.

 

StoreTransaction nosum of sales $merch only salesservice sales
1123150001500
21246006000
21266006000
31254504500

 

I am also open to prepping the data with some M in power query, but any suggestions are appreciated.

 

Thanks!

1 ACCEPTED SOLUTION
3 REPLIES 3
dax
Community Support
Community Support

Hi @Anonymous , 

You also could use below Mcode to achieve your goal.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0MgaSualFyRlA2tzAQClWB1mmPLGoKDGvpBIkYIoumZlXXJKYk4NVDmakKdRII7CMCZKMGVTGGCxjiiRjYoqsxwxdTywA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Store = _t, #"Transaction no" = _t, #"product type" = _t, #"sales $" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Store", Int64.Type}, {"Transaction no", Int64.Type}, {"product type", type text}, {"sales $", Int64.Type}}),
    #"Grouped Rows1" = Table.Group(#"Changed Type", {"Store", "Transaction no"}, {{"Count", each  Text.Combine([product type], ","), type number}, {"aa", each _, type table [Store=number, Transaction no=number, product type=text, #"sales $"=number]}}),
    Custom1 = Table.ReplaceValue(#"Grouped Rows1", each [Count], each if Text.Contains([Count], "install") or Text.Contains([Count], "warranty") then "service" else "merch only", Replacer.ReplaceValue,{"Count"}),
    #"Expanded aa" = Table.ExpandTableColumn(Custom1, "aa", {"product type", "sales $"}, {"product type", "sales $"})
in
    #"Expanded aa"

547.PNG

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.

az38
Community Champion
Community Champion

Hi @Anonymous 

 

try measures:

sum of sales $ = calculate(sum([sales $]);ALLEXCEPT('Table';'Table'[Store];'Table'[Transaction no]))

then

service sales = 
var _isMerch = calculate(distinctcount('Table'[product type]);ALLEXCEPT('Table';'Table'[Store];'Table'[Transaction no]);'Table'[product type]<>"Merch")
return 
if(_isMerch>0;[sum of sales $];0)

then

merch only sales = [sum of sales $]-[service sales]

 

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

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.