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

Percentage between 2 columns - DAX Synthax

Hi the community, 

 

I'm starting in Power BI and generaly in data science, and for this reason i have a problem which look very simple but i'm breaking my head agains my office since too much time to solve it. 

 

Please find below my data : 

 

Vendor nameConditionOrder Quantity
Aero IncScrap9000
Aero IncOverhaul1000
Jack AeroScrap5000
Jack AeroOverhaul1000
Mr. Jacket enterpriseScrap1500
Mr. Jacket enterpriseOverhaul25000

 

Etc... 

 

I would like to find a formula for calculate the percentage of scrap part and overhaul part by vendor compare to the total quantity order. 

 

Or, maybe i need to do a new column ? 

 

Honnestly, i know it's look simple... But i didn't have the logic. 

 

Thanks for your help ! 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Or you might want this variation of the measure:

[% Scrap] =
VAR __scrap =
	CALCULATE(
		[Total Order],
		KEEPFILTERS(Sheet1[Condition] = "scrap")
	)
VAR __total =
	CALCULATE(
		[Total Order],
		ALL( Sheet1[Condition] )
	)
RETURN
	DIVIDE(__scrap, __total)

 

Best

D

View solution in original post

10 REPLIES 10
vivran22
Community Champion
Community Champion

Hello @Anonymous 

 

Welcome to the Power BI community.

 

You can achieve this by creating new measures:

 

Total Order = SUM(dtTable[Order Quantity])

%Scrap = 
VAR SCRAP =
    CALCULATE ( [Total Order], FILTER ( dtTable, dtTable[Condition] = "Scrap" ) )
RETURN
    DIVIDE ( SCRAP, [Total Order] )

%Overhaul = 
VAR OVERHAUL =
    CALCULATE ( [Total Order], FILTER ( dtTable, dtTable[Condition] = "Overhaul" ) )
RETURN
    DIVIDE ( OVERHAUL, [Total Order] )

 

It will give you following results:

 

Rafael.PNG

Regards,
Vivek

If it helps, please mark it as a solution

Kudos would be a cherry on the top 🙂

Connect on LinkedIn

Anonymous
Not applicable

Questionask.png

 

I do a new measure separate for the total order. 

 

I did'nt understand why i have one in Value with your formula ? 

 

Thanks again for your help... 

Anonymous
Not applicable

@vivran22,

 

There's a golden rule of data modelling in Power BI: Never filter a table when you can filter a column. There are very good reasons behind this (also related to performance) but if you want to know more about it, you'll need to find the relevant articles on www.sqlbi.com, where the ultimate knowledge about DAX resides.

 

As for the original question itself... The measures should be written this way:

 

[Total Order] = SUM(dtTable[Order Quantity])

%Scrap = 
VAR __scrap =
    CALCULATE (
       [Total Order],
       KEEPFILTERS(dtTable[Condition] = "Scrap")
    )
var __total = [Total Order]
RETURN
    DIVIDE ( __scrap, __total )

%Overhaul = 
VAR __overhaul =
    CALCULATE ( 
        [Total Order],
        KEEPFILTERS( dtTable[Condition] = "Overhaul" )
    )
var __total = [Total Order]
RETURN
    DIVIDE ( __overhaul, __total )

Best

darlove

Anonymous
Not applicable

Darlove, 

 

I have the same problem. I get one in values with this formula. Where i did wrong ? 

 

Questionask2.png

 

I apologize if its obvious... thanks for your help. 

 

Best 

@Anonymous 

 

I believe it is the formatting issue. Select the measure(%Scrapping) > Go to Measure Tools > And select the % formatting. It should resolve this.

 

Cheers!
Vivek

If it helps, please mark it as a solution
Kudos would be a cherry on the top 🙂

https://www.vivran.in/

Connect on LinkedIn

Anonymous
Not applicable

No it did'nt still work. 

I try to changed the formula like this : 

 

  1. %Overhaul =
    VAR __overhaul = CALCULATE([Total Order], Sheet1[Condition ] = "overhaul")
    var __total = [Total Order]
    RETURN
    DIVIDE(__overhaul, __total)

 

It's worked for the the total overhaul and scrap. 


Questionask3.png

But i can't have the scrap ration by example, for each vendor compare to the total. In fact, the result like you see doesnt make any sense for each one. 

I tried to add a new measure like that : 

 

  1. Just Scrap =
    VAR __scrap = CALCULATE([Total Order], KEEPFILTERS(Sheet1[Condition ] = "scrap"))
    VAR __total = [Total Order]
    RETURN
    DIVIDE(__scrap, __total)

    But i had again 1 in value... 

    Could you please advise me ? 

    Your coments are very helpful, thank you so much. 
Anonymous
Not applicable

Or you might want this variation of the measure:

[% Scrap] =
VAR __scrap =
	CALCULATE(
		[Total Order],
		KEEPFILTERS(Sheet1[Condition] = "scrap")
	)
VAR __total =
	CALCULATE(
		[Total Order],
		ALL( Sheet1[Condition] )
	)
RETURN
	DIVIDE(__scrap, __total)

 

Best

D

Anonymous
Not applicable

Awesome ! 

Thank you a lot Dar for you clearly explanations. Help me a lot for the future and my understanding of DAX synthax ! 

Wish you the best  ! 

🙂 

Anonymous
Not applicable

This should work:

[% Scrap] =
VAR __scrap =
	CALCULATE(
		[Total Order],
		KEEPFILTERS(Sheet1[Condition] = "scrap")
	)
VAR __total = [Total Order]
RETURN
	DIVIDE(__scrap, __total)

I must work. Bear in mind though, that when you filter by Overhaul, then this will return 0 out of necessity and if you filter by Scrap, it'll return 1 (100%). This is correct. If you don't select from the Condition, then you'll get the % of scrap in the selection. Change 'scrap' to 'overhaul' and you'll get the same behavior for Overhaul.

 

Best

D

Anonymous
Not applicable

Create measure
Total scrap quantity= calculAte(sum(table[quantity]),filter(table,table[condition]="scrap")

Similarly calculate for overhaul.

If you want to compare it with total use below dax measure
Total= sum(table[quantity])

Thanks
Pravin

If it resolves your problem mark it as a solution and give Kudos.

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.

Top Solution Authors