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
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
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.