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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Calculate % of Difference from higher hierarchy level (Sum)

Hi all!

I need to divide the difference between first and second column (Infeed-Discharge or Spoilage #) with the Sum of "Cupper" Infeed (highlighted in red). It needs to work both for top level and lower level of "Machine Type". It works now for top but not for bottom, as seen in "Spoilage %" column.

Hopefully I made myself clear. Would appreciate any help on this. Thanks much!

 

attach.jpg

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Modify the _total variable as below:

var _total=CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),'Table'[Machine Type]="Cupper"))

 For the whole dax expression is as below:

Measure = 
var _discharge=CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Category]="Discharge"))
var _infeed=CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Category]="Infeed"))
var _total=CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),'Table'[Machine Type]="Cupper"))
Return
IF(ISINSCOPE('Table'[Category]),SUM('Table'[Value]),FORMAT(DIVIDE(ABS(_discharge-_infeed),_total),"percent"))

And you will see:

v-kelly-msft_0-1608863112796.png

 

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

View solution in original post

8 REPLIES 8
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

First transform table into below format:

v-kelly-msft_0-1608799231523.png

Then create a measure as below:

Measure = 
var _discharge=CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Category]="Discharge"))
var _infeed=CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Category]="Infeed"))
var _total=CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),'Table'[Category]=MAX('Table'[Category])&&'Table'[Machine Type]=MAX('Table'[Machine Type])))
Return
IF(ISINSCOPE('Table'[Category]),SUM('Table'[Value]),FORMAT(DIVIDE(ABS(_discharge-_infeed),_total),"percent"))

And you will see:

v-kelly-msft_1-1608799275620.png

 

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

Anonymous
Not applicable

Hi v-kelly-msft,

thanks for your feedback but the % calculation denominator should always be the "Cupper" Infeed - Sum of "sub set" where Machine Type = Cupper.

Hi @Anonymous ,

 

Modify the _total variable as below:

var _total=CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),'Table'[Machine Type]="Cupper"))

 For the whole dax expression is as below:

Measure = 
var _discharge=CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Category]="Discharge"))
var _infeed=CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Category]="Infeed"))
var _total=CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),'Table'[Machine Type]="Cupper"))
Return
IF(ISINSCOPE('Table'[Category]),SUM('Table'[Value]),FORMAT(DIVIDE(ABS(_discharge-_infeed),_total),"percent"))

And you will see:

v-kelly-msft_0-1608863112796.png

 

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

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

Ashish_Mathur
Super User
Super User

Hi,

Does this measure work?

=divide([spoilage #],calculate([spoilage #],data[machine type]="Cupper"))


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi Ashish_Mathur,

it does only for upper hierarchy level (bolded rows) - that's my Spoilage % column, but not for lower. Btw, the denominator should be the Sum of "Cupper" Infeed.

Hi,

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
ryan_mayu
Super User
Super User

@Anonymous 

hope I understand your request clearly.

Diff = sum('Table (2)'[Infeed])-sum('Table (2)'[Dicharge])


Measure 3 = DIVIDE([Diff],CALCULATE(sum('Table (2)'[Infeed]),ALLEXCEPT('Table (2)','Table (2)'[Machine Type])))

1.png





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

Proud to be a Super User!




Anonymous
Not applicable

Hi ryan_mayu,

thanks for feedback!

You're close but the denominator for Measure 3 should always be the Sum of "Cupper" Infeed, when calculating any level or hierarchy.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.