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
AmiraBedh
Resident Rockstar
Resident Rockstar

Calculating the average rate based on specific conditions

I have the following T-SQL query :

 

SELECT
(SUM(CASE WHEN DFP.status = 'ON'
THEN FVD.metric_rep * FVD.consumption
ELSE 0 END) /
SUM(CASE WHEN DFP.status = 'ON'
THEN FVD.consuption
ELSE 0 END)) * 100 AS RateRTC

 

FROM FactVenteDetails AS FVD
LEFT JOIN DimStatus AS DFP
ON FVD.fk_status = DFP.sk_status

 

The query is defining the average rate based on this formula : 

 

100x (M1xTC1 + M2xTC2 ....)​/(M1+M2 ...)

Where M is the FVD.metric_rep and the TC is theFVD.consumption

How can I translate it to DAX ?

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696
1 ACCEPTED SOLUTION
amirabedhiafi
Impactful Individual
Impactful Individual

YourMeasure =

var test =

CALCULATE(SUM(FVD[metric_rep] * FVD[consumption] ), DFP[status] = "ON")

 

var test2 = CALCULATE(sum(FVD[consuption]),DFP[status] = "ON")

 

return  DIVIDE(test,test2,0)

Amira Bedhiafi
Full Stack Business Intelligence Consultant @Capgemini

View solution in original post

3 REPLIES 3
AmiraBedh
Resident Rockstar
Resident Rockstar

@amitchandak  and @amirabedhiafi  what is the difference between the solutions you provided?

I am curious if it doesn't give the same result ?


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696
amirabedhiafi
Impactful Individual
Impactful Individual

YourMeasure =

var test =

CALCULATE(SUM(FVD[metric_rep] * FVD[consumption] ), DFP[status] = "ON")

 

var test2 = CALCULATE(sum(FVD[consuption]),DFP[status] = "ON")

 

return  DIVIDE(test,test2,0)

Amira Bedhiafi
Full Stack Business Intelligence Consultant @Capgemini
amitchandak
Super User
Super User

@AmiraBedh ,

calculate( divide( Sumx(FVD,FVD[metric_rep] * FVD[consumption]) ,sum(FVD[consuption])), Filter(DFP , DFP[status] = "ON") )

 

You need have a join between two tables in power bi

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.