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
Anonymous
Not applicable

IF statement doesn't work when using value range

I am trying to understand why Power BI does not compute my DAX IF statement when I introduce a value range (value1 < x < value2)

 

When I create a column using this DAX expression, the column is created with no issues:

 
DistanceFromOffice = IF(0<'HR Analytics Data'[DistanceFromHome],"Close")
 
But, when I introduce an upper range to the expression: DistanceFromOffice = IF(0<'HR Analytics Data'[DistanceFromHome]<5,"Close")
 
I get the following error: DAX comparison operations do not support comparing values of type True/False with values of type Integer. Consider using the VALUE or FORMAT function to convert one of the values.
 
I am aware that I could achieve the desired column using a SWITCH expression but I'm more so trying to understand why my IF statement doesn't work - what does it mean by 'comparing values of true/false with values of type integer'? 
2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

Please try writing calculated column formula something like below.

 

DistanceFromOffice =
IF (
    0 < 'HR Analytics Data'[DistanceFromHome]
        && 'HR Analytics Data'[DistanceFromHome] < 5,
    "Close"
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

ribisht17
Super User
Super User

@Anonymous 

 

The product of 0<'HR Analytics Data'[DistanceFromHome] with be either TRUE or FALSE

 

But then you are trying to equate this with < 5 which is a number

 

So your equation is TRUE/FALSE(0<'HR Analytics Data'[DistanceFromHome]) < 5 hence failing

 

You can use && to give it a context like below as you are giving multiple conditions here

 

Thanks,

Ritesh

Mark my post as a solution if it helped you| Munde and Kudis (Ladies and Gentlemen) I like your Kudos!! !!
My YT Channel Dancing With Data !! Connect on Linkedin !! PL 300 Certification Series

 

 

View solution in original post

2 REPLIES 2
ribisht17
Super User
Super User

@Anonymous 

 

The product of 0<'HR Analytics Data'[DistanceFromHome] with be either TRUE or FALSE

 

But then you are trying to equate this with < 5 which is a number

 

So your equation is TRUE/FALSE(0<'HR Analytics Data'[DistanceFromHome]) < 5 hence failing

 

You can use && to give it a context like below as you are giving multiple conditions here

 

Thanks,

Ritesh

Mark my post as a solution if it helped you| Munde and Kudis (Ladies and Gentlemen) I like your Kudos!! !!
My YT Channel Dancing With Data !! Connect on Linkedin !! PL 300 Certification Series

 

 

Jihwan_Kim
Super User
Super User

Hi,

Please try writing calculated column formula something like below.

 

DistanceFromOffice =
IF (
    0 < 'HR Analytics Data'[DistanceFromHome]
        && 'HR Analytics Data'[DistanceFromHome] < 5,
    "Close"
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

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.