cancel
Showing results for
Did you mean:

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Helper III

## 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:

 Date Status 15/10/2022 1 16/10/2022 1 17/10/2022 1 18/10/2022 1 19/10/2022 2 20/10/2022 2 21/10/2022 2 22/10/2022 2 23/10/2022 3 24/10/2022 3 25/10/2022 3 26/10/2022 3

Someone can help me?

Thanks a lot!

1 ACCEPTED SOLUTION
Memorable Member
``````Status = If( date >= DATEVALUE("2022-10-15") && date <= DATEVALUE("2022-10-18"), "1",
...``````
6 REPLIES 6
Super User

HI @vinicius_ramos

``````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
)``````
Continued Contributor

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"
)))

Regards,

Nikhil Chenna

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

Continued Contributor

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"
)))

Regards,

Nikhil Chenna

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

Memorable Member

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.

Memorable Member
``````Status = If( date >= DATEVALUE("2022-10-15") && date <= DATEVALUE("2022-10-18"), "1",
...``````
Helper III

Thanks a lot.

Announcements

#### Power BI Monthly Update - November 2023

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

#### Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

#### The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors