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
Bananathan
Frequent Visitor

IF Statement does the opposite of what I've typed

So I'm very confused and I've probably missed something obvious but I have these two dates. The one on the left is a selected date in a slicer and the one on the right is the date from a row of data I'm trying to compare: 

Bananathan_0-1662640608622.png

And this measure: (Above date on left is End_of_Month and date on right is [Contractual Leave Date])

VAR End_of_Month = EOMONTH( SELECTEDVALUE('Date Table for Measures'[Date]),0 )
RETURN
IF(
    'HR Turnover Data'[Contractual Leave Date] > End_of_Month,
    "True",
    "False"
    )

 

The statement returns true for the above and switching to a less than sign returns false. Essentially the opposite of what my data would suggest. Any ideas why this is happening?

 

Edit 1: To add, I've noticed the measure DOES work for dates larger than the selected date, it just also returns true for dates below the selected date. Anything blank it returns as FALSE, so something seems to be wrong with the dates. The format of each is the same and I have other measures using the exact same two dates that work perfectly fine.

1 ACCEPTED SOLUTION
Adescrit
Impactful Individual
Impactful Individual

To align the formula with the conditions in your screenshot, you would need to wrap the Contractual Leave Date in a MIN() function. When you add a date column containing mul;tiple date values to a card visual, by default it will return the "Earliest" dates (which is equivalent to the minimum date in the column. 

 

So to align your measure with the conditions in the two cards the DAX would be:

 

VAR End_of_Month = EOMONTH( SELECTEDVALUE('Date Table for Measures'[Date]),0 )
RETURN
IF(
    MIN('HR Turnover Data'[Contractual Leave Date]) > End_of_Month,
    "True",
    "False"
    )

Did I answer your question? Mark my post as a solution!
My LinkedIn

View solution in original post

2 REPLIES 2
Adescrit
Impactful Individual
Impactful Individual

To align the formula with the conditions in your screenshot, you would need to wrap the Contractual Leave Date in a MIN() function. When you add a date column containing mul;tiple date values to a card visual, by default it will return the "Earliest" dates (which is equivalent to the minimum date in the column. 

 

So to align your measure with the conditions in the two cards the DAX would be:

 

VAR End_of_Month = EOMONTH( SELECTEDVALUE('Date Table for Measures'[Date]),0 )
RETURN
IF(
    MIN('HR Turnover Data'[Contractual Leave Date]) > End_of_Month,
    "True",
    "False"
    )

Did I answer your question? Mark my post as a solution!
My LinkedIn
tamerj1
Super User
Super User

@Bananathan 
is [Contractual Leave Date] a measure or a column? In the screenshot it says "Earliest" which has to be considered in the calculation. Please provide more context.

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.

Top Solution Authors