Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

date category in query editor

Hello,

 

I would like to create a custom column into query editor which give the date category as follow

if date1 is null then 'No Data'

if date1 - today() < 0 then 'Date Past'

if date1 - today() <=30 then '0 - 30 Days'

else '+ 30 Day'.

 

The if function work but it does not recognized the value of today()

 

Does someone know how to do this calculation

Thanks in advance for your help.

 

1 ACCEPTED SOLUTION
Nathaniel_C
Community Champion
Community Champion

Hi @Anonymous ,

You need to use

 DateTime.Date(DateTime.LocalNow()))

You may want to go to this posting, I included my pbix at the end

Using the today function

 

Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel

 





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

Proud to be a Super User!




View solution in original post

4 REPLIES 4
Nathaniel_C
Community Champion
Community Champion

Hi @Anonymous ,

You need to use

 DateTime.Date(DateTime.LocalNow()))

You may want to go to this posting, I included my pbix at the end

Using the today function

 

Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel

 





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

Proud to be a Super User!




Anonymous
Not applicable

For the community, Here's the final code:

 

if [Date1] is null then "No Data" else
if (Duration.Days(DateTime.Date([Date1])-DateTime.Date(DateTime.LocalNow()))) < 0 then "Date Past"

else if (Duration.Days(DateTime.Date([Date1])-DateTime.Date(DateTime.LocalNow()))) >= 0 and
(Duration.Days(DateTime.Date([Date1])-DateTime.Date(DateTime.LocalNow()))) <= 30
then "0 - 30 Days"
else if (Duration.Days(DateTime.Date([Date1])-DateTime.Date(DateTime.LocalNow()))) > 30 and
(Duration.Days(DateTime.Date([Date1])-DateTime.Date(DateTime.LocalNow()))) <= 60
then "31 - 60 Days"
else if (Duration.Days(DateTime.Date([Date1])-DateTime.Date(DateTime.LocalNow()))) > 60 and
(Duration.Days(DateTime.Date([Date1])-DateTime.Date(DateTime.LocalNow()))) <= 90
then "61 - 90 Days" else "+ 90 Days"

Hi @Anonymous ,

Good job! You might also look into using SWITCH() in these situations with variables to make debug easier.

Nathaniel





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

Proud to be a Super User!




Anonymous
Not applicable

Thank you!  In Query Editor, if you are adding a custom column, does the switch function will works?

 

If you could provide me a simple example with a custom column in Query editor, I will be glad to test it.

Best Regards,

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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