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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

Date Calculation

Hello, 

 

I need to do a something like "IF" with dates, for example: 

 

Status = If( date between "2022-10-15" and "2022-10-18", "1",
                    If( date between "2022-10-19" and "2022-10-22", "2",

                                     If( date between "2022-10-23" and "2022-10-26", "3", "null")))

 

and returns the results: 

DateStatus
15/10/20221
16/10/20221
17/10/20221
18/10/20221
19/10/20222
20/10/20222
21/10/20222
22/10/20222
23/10/20223
24/10/20223
25/10/20223
26/10/20223

 

Someone can help me?

 

Thanks a lot!

1 ACCEPTED SOLUTION
lukiz84
Memorable Member
Memorable Member

Status = If( date >= DATEVALUE("2022-10-15") && date <= DATEVALUE("2022-10-18"), "1",
...

View solution in original post

6 REPLIES 6
tamerj1
Super User
Super User

HI @Anonymous 
Please try

Status =
SWITCH (
    TRUE (),
    'Table'[Date] >= DATE ( 2022, 10, 15 )
        && 'Table'[Date] >= DATE ( 2022, 10, 18 ), 1,
    'Table'[Date] >= DATE ( 2022, 10, 19 )
        && 'Table'[Date] >= DATE ( 2022, 10, 22 ), 2,
    'Table'[Date] >= DATE ( 2022, 10, 23 )
        && 'Table'[Date] >= DATE ( 2022, 10, 26 ), 3
)
NikhilChenna
Continued Contributor
Continued Contributor

Hi @vinicius_ramos ,

I have personally tried this and it worked out. 

 

You can achieve the above by creating a dax calculated column = 

 

Status_column =

IF( 'Date'[Date]>="2022-10-15"  &&  'Date'[Date]<="2022-10-18"), "1",
IF( 'Date'[Date]>="2022-10-19"  &&  'Date'[Date]<= "2022-10-19"), "2",
IF('Date'[Date]>= "2022-10-23" &&  'Date'[Date]<= "2022-10-26"), "3","null"
)))

 

this will solve your issue.

 

Regards,

Nikhil Chenna

 

Please apprecitate with Kudos, and accept this post as a solution if it works.

NikhilChenna
Continued Contributor
Continued Contributor

Hi @Anonymous ,

I have personally tried this and it worked out. 

 

You can achieve the above by creating a dax calculated column = 

 

Status_column =

IF( 'Date'[Date]>="2022-10-15"  &&  'Date'[Date]<="2022-10-18"), "1",
IF( 'Date'[Date]>="2022-10-19"  &&  'Date'[Date]<= "2022-10-19"), "2",
IF('Date'[Date]>= "2022-10-23" &&  'Date'[Date]<= "2022-10-26"), "3","null"
)))

 

this will solve your issue.

 

Regards,

Nikhil Chenna

 

Please apprecitate with Kudos, and accept this post as a solution if it works.

This won't work for a calculated column and is a time intelligence function to get a table of dates which are between start and end date.

lukiz84
Memorable Member
Memorable Member

Status = If( date >= DATEVALUE("2022-10-15") && date <= DATEVALUE("2022-10-18"), "1",
...
Anonymous
Not applicable

@lukiz84 

 

Thanks a lot.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.