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
bo_afk
Post Patron
Post Patron

Sum by multiple columns

Hi,

 

I have some stock data that shows products sent out and products returned, along with return reasons (row 2,3,4). I also have numbers for those sent out but not returned (row 1). 

 

What I would like to work out is the rate of products returned for each reason and category. And this is calculated as the number of return divided by the total of products out by a particular set of variables (categories). 

 

I need to get a measure/column that calculates this total product out by the set categories

 

e.g. In the sample below where market = abc, cat1=adult, cat2=womenswear, cat3=accessories and cat4=belt, the total is 153 (90+11+26+26).

 

At the moment, if i calculate in-rate, they come up as 100% which is wrong.

 

Sample data output

RowMarketCat1Cat2Cat3Cat4Reas1Reas2OutReturnIn Rate
1abcAdultWomenswearAccessoriesBelts  90  
2abcAdultWomenswearAccessoriesBeltsFitBig1111100%
3abcAdultWomenswearAccessoriesBeltsOtherUnknown2626100%
4abcAdultWomenswearAccessoriesBeltsStylingUnsuitable2626100%

 

 

Desired data output

RowMarketCat1Cat2Cat3Var4Reas1Reas2OutReturnIn Rate
1abcAdultWomenswearAccessoriesBelts  90  
2abcAdultWomenswearAccessoriesBeltsFitBig11117%
3abcAdultWomenswearAccessoriesBeltsOtherUnknown262617%
4abcAdultWomenswearAccessoriesBeltsStylingUnsuitable262617%

 

The total in rate for cat4=belts is 43% - total in (63)/total out (153)

 

Hope this all makes sense and many thanks for your help!

 

 

afk

1 ACCEPTED SOLUTION
Baskar
Resident Rockstar
Resident Rockstar

Cool try this 

 

Percentage = SUM(Com1[Return])/CALCULATE(SUM(Com1[Out]),ALLEXCEPT(Com1,Com1[Cat4]))
 
Capture.PNG

View solution in original post

4 REPLIES 4
Baskar
Resident Rockstar
Resident Rockstar

Hey can you please try this :

 

Measure 2 = SUM(Com1[Return])/CALCULATE(SUM(Com1[Out]),ALL(Com1))
 
Capture.PNG

Thanks for your suggestion @Baskar.

 

But it doesn't seem to work in my data. In the sample data set it does, but i actually have more values for each of the categories which could be the reason why it's not working.

 

Please see below:

Snap1.JPG

 

Can you advise further?

Baskar
Resident Rockstar
Resident Rockstar

Cool try this 

 

Percentage = SUM(Com1[Return])/CALCULATE(SUM(Com1[Out]),ALLEXCEPT(Com1,Com1[Cat4]))
 
Capture.PNG

Thanks @Baskar, this has worked! Smiley Very Happy

 

However I made a small change in the "allexcept" part where I included all the cat columns as opposed to just cat4. I assume this allows the correct calculations when grouped by any of the categories. Do correct me if I'm wrong though.

 

 

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.