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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
robertoz
Advocate I
Advocate I

Measure with IF statement and filter context

Dear all,

I am curious, wheter this is possible.

Within calculated measure I am trying to calculate alternative results depending on the dimension. Let me explain on an demo/example:

I have got Table:

 

ItemAmountMonth
EBIT1Jan
EBIT2Feb
EBIT1Mar
Revenue20Jan
Revenue20Feb
Revenue40Mar
EBIT%0,05Jan
EBIT%0,1Feb
EBIT%0,25Mar

 

Sum Amount = SUM('Table'[Amount]) returns sums as expected. However for EBIT% I can NOT use Sum.  I do need to substitute Sum with (Sum of EBIT / Sum of Revenue). So I tried:

 

Measure1 = SUMX('Table'; IF('Table'[Item] <> "EBIT%"; CALCULATE(SUM('Table'[Amount])); CALCULATE(SUM('Table'[Amount]); 'Table'[Item] = "EBIT") / CALCULATE(SUM('Table'[Amount]); 'Table'[Item] = "Revenue")))

BUT it returns null for EBIT%:

 Result.PNG

It looks like Filters in CALCULATE do not work as expected or I do have some mistake.

 

Any Ideas?

 

Rem.: I know, I can create separate measure for EBIT%, however I do need to put all 3 Measures (Revenue / EBIT / EBIT% into one colum, like displayed above.

 

Thanks lot for your support.

2 ACCEPTED SOLUTIONS
Omega
Impactful Individual
Impactful Individual

Try using the below measure: 

 

Measure = SWITCH(TRUE(),
        MAX(Table1[Item]) = "EBIT", SUM(Table1[Amount]),
        MAX(Table1[Item])= "EBIT%",CALCULATE(SUM(Table1[Amount]),Table1[Item] = "EBIT")/CALCULATE(SUM(Table1[Amount]),Table1[Item]="Revenue"),
        CALCULATE(SUM(Table1[Amount]),Table1[Item]="Revenue"))

View solution in original post

Omega
Impactful Individual
Impactful Individual

HYG. I calculated EBIT% as a variable and used Format function to change the format 🙂 

 

Measure = 
var EB = CALCULATE(SUM(Table1[Amount]),Table1[Item] = "EBIT")/CALCULATE(SUM(Table1[Amount]),Table1[Item]="Revenue")
return
SWITCH(TRUE(),
        MAX(Table1[Item]) = "EBIT", SUM(Table1[Amount]),
        MAX(Table1[Item])= "EBIT%",FORMAT(EB,"Percent"),
        CALCULATE(SUM(Table1[Amount]),Table1[Item]="Revenue"))

View solution in original post

6 REPLIES 6
Omega
Impactful Individual
Impactful Individual

Try using the below measure: 

 

Measure = SWITCH(TRUE(),
        MAX(Table1[Item]) = "EBIT", SUM(Table1[Amount]),
        MAX(Table1[Item])= "EBIT%",CALCULATE(SUM(Table1[Amount]),Table1[Item] = "EBIT")/CALCULATE(SUM(Table1[Amount]),Table1[Item]="Revenue"),
        CALCULATE(SUM(Table1[Amount]),Table1[Item]="Revenue"))

@Omega

G8! many thanks.

So the "magic" is, if I need to refer to dimension within IF/SWICH condition, I need to pack the dimension into function.

Btw. also this works:

 

Measure 3 = SWITCH(TRUE();
        MAX('Table'[Item])= "EBIT%"; CALCULATE(SUM('Table'[Amount]); 'Table'[Item] = "EBIT")/CALCULATE(SUM('Table'[Amount]); 'Table'[Item]="Revenue"); 
        CALCULATE(SUM('Table'[Amount])))

 and wit IF as well:

 

 

MeasureIF = IF(MAX('Table'[Item])= "EBIT%";
CALCULATE(SUM('Table'[Amount]); 'Table'[Item] = "EBIT")/CALCULATE(SUM('Table'[Amount]);'Table'[Item]="Revenue"); CALCULATE(SUM('Table'[Amount])))

 

Thanks a lot.

R.

Omega
Impactful Individual
Impactful Individual

You are right! I thought you need to use the amount of Revenue when you don't select EBIT or EBIT% and that's why I used Switch ()

 

 

yes. thanks.

One related question came to my mind: now I have results in one table:

Item         Measure

EBIT            4

Revenue   80

EBIT %     0.4

 

Is there a trick, to get %-sign for EBIT %?

Means:

Item        Measure

EBIT            4

Revenue   80

EBIT %     0.4%

 

Thx.

Omega
Impactful Individual
Impactful Individual

HYG. I calculated EBIT% as a variable and used Format function to change the format 🙂 

 

Measure = 
var EB = CALCULATE(SUM(Table1[Amount]),Table1[Item] = "EBIT")/CALCULATE(SUM(Table1[Amount]),Table1[Item]="Revenue")
return
SWITCH(TRUE(),
        MAX(Table1[Item]) = "EBIT", SUM(Table1[Amount]),
        MAX(Table1[Item])= "EBIT%",FORMAT(EB,"Percent"),
        CALCULATE(SUM(Table1[Amount]),Table1[Item]="Revenue"))

Works lika a charm.

Many thanks for your support.

R.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.