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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Use If() function as measure or calculated column with different results

I am trying to use IF() function to create a measure and put it into a matrix, but the following two screenshots showed me no column selection when I am trying to give a condition statement to IF() function. The column I am going to refer to is "S/T" (which shows in the third graph, it is a column created by PowerQuery Editor). 

The complete measure that I would like to make is as below:

Turnaround Time / Box = 
    IF('new vessel'[S/T]="S", 
       CALCULATE(AVERAGEX('new vessel', 
                 'new vessel'[New Off Chassis Time]-'new vessel'[New Hot Time]),
                 ALLEXCEPT('new vessel','new vessel'[Tractor Cycle Id])
                ), 
       CALCULATE(AVERAGEX('new vessel', 
                 'new vessel'[New Off Chassis Time]-'new vessel'[New Hot Time]),
                 ALLEXCEPT('new vessel', 'new vessel'[Tractor Cycle Id])
                )
      )

hyman9090_0-1669632522726.pnghyman9090_1-1669632535846.png

 

hyman9090_2-1669632744515.png

 

To handle this situation, I tried to turn into using calculated column instead of using measure. And turns out it works.

hyman9090_4-1669633950350.png

 

Can someone explain a little bit why the IF() function is so interesting that it works only in calculated column? Or how can I do to make it work in measure?

 

 

 

1 ACCEPTED SOLUTION
mangaus1111
Solution Sage
Solution Sage

Because in the measures there is no row context, but only filter context.

 

This is why you need a column as first parameter of the IF function if you want to create a calculated column, instead if you want to create a measure, the first parameter does not accept a column.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
mangaus1111
Solution Sage
Solution Sage

Because in the measures there is no row context, but only filter context.

 

This is why you need a column as first parameter of the IF function if you want to create a calculated column, instead if you want to create a measure, the first parameter does not accept a column.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

mangaus1111
Solution Sage
Solution Sage

Hi @Anonymous ,

try to use in the measure

IF(SELECTEDVALUE('new vessel'[S/T]) = "S"

 

 

Anonymous
Not applicable

Nice, it works. But I am wondering why it works, and why my original approach doesn't work? 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors