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
MohsinBipu
Helper I
Helper I

DateTime with If condition

I have shared a simple dummy chart.  I want to convert the date with the below 03 conditions-

1. If the Date does not exist, then it will return "N/A"

2. If the Date is less than today's date, then it will return Date

3. If the date is higher than today's date, then it will return "Est.  Date".

 

I using the below code, but this is not working.

if Value.Is(Number.From(DateTime.FromText([Date]) ), type number)
then
if DateTime.FromText([Date]) < DateTime.LocalNow() then
[Date]
else "Est. " & [Date]
else "N/A"

 

 

PowerBI Datetime.png

 

1 ACCEPTED SOLUTION

not([Date] is datetime)

View solution in original post

9 REPLIES 9
MohsinBipu
Helper I
Helper I

Magic 😄

MohsinBipu
Helper I
Helper I

@wdx223_Daniel I have facing a Date format issue. your formula is giving DateTime format whereas I am looking for Date format only as in below picture.PowerBI Datetime.png

 

=if not([Date] is datetime) then "N/A" else (if [Date]< DateTime.LocalNow() then "" else "Est. ")&DateTime.ToText([Date],"dd/MM/yyyy")

MohsinBipu
Helper I
Helper I

@wdx223_Daniel your formula is working fine. can you please advise what was the mistake in my formula?

there are many data type in your data. DateTime.FromText is only used to convert Text to DateTime,  So, your first two conditions will get errors  when the value is a datetime already. And, Text and DateTime can not be concatenated directly, that will give a error too.

MohsinBipu
Helper I
Helper I

@wdx223_Daniel is working fine. you are great.

=if not([Date] is datetime) then "N/A" else if [Date]< DateTime.LocalNow() then [Date] else "Est. "&DateTime.ToText([Date])

MohsinBipu
Helper I
Helper I

@wdx223_Daniel  Thanks for your quick response. But I am getting only "N/A". Please see the below snapshot.  I do not change my data to Date format, Please see the below mark in the snapshot.  I dont want to change the data format to DATE. I want to solve it with a formula. Please help.

 

MohsinBipu_0-1676010391891.png

 

not([Date] is datetime)

wdx223_Daniel
Community Champion
Community Champion

if not([Date] is date) then "N/A" else if  [Date]< DateTime.LocalNow() then [Date] else "Est. "&DateTime.ToText([Date])

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.

Top Solution Authors