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
DvdH
Helper V
Helper V

Create a new column on if statement(Very basic support needed)

Hi im trying the most simple query. Any help?

 

 

if ([Actual End Date] < [Target End Date])
    then 1
        else 0

 

 

If date1 is less then date2 then put 1 in the column otherwise put 0.
Error: Expression.Error: We cannot convert the value null to type Logical.
Support? 

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

if ([Actual End Date] ?? #date(1,1,1)) < ([Target End Date] ?? #date(1,1,1)) then 1 else 0

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

8 REPLIES 8
CNENFRNL
Community Champion
Community Champion

if ([Actual End Date] ?? #date(1,1,1)) < ([Target End Date] ?? #date(1,1,1)) then 1 else 0

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Hi thanks for answering. I need to do the same thing but replace [Actual End Date] with Today() or something which works simular:

if (DateTime.Now() < ([Target End Date] ?? #date(1,1,1)) then 1 else 0

 Something simular to above should work. Any support?

if (DateTime.LocalNow() <...

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

Ahh never thought to use the ?? In an if comparison--very cool.

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
watkinnc
Super User
Super User

You have a null in one of your date fields,  so null > date isn't valid. Try each if is null [Actual End Date] or [Actual End Date] < [Target End Date] then 1 else 0

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
KeyurPatel14
Resolver IV
Resolver IV

KeyurPatel14_0-1677837838095.png

I have tried on this dummy data and it is working as per your requirement.
I added one custom column with the formula mentioned below:

KeyurPatel14_1-1677837970651.png

Try this and if my solution solves your doubt then please consider it as a solution.

 

Einomi
Resolver II
Resolver II

Hi @DvdH 

We need more info, I did a test on a simple dataset and it works...send us more code

6677028
Frequent Visitor

It is very difficult for someone to help you in this case. if only this formula is not wrong. but it is used with many other formulas to know where is wrong.

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
Top Kudoed Authors