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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount 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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Kudoed Authors