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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
AmiraBedh
Super User
Super User

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
Super User
Super User

@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

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.