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
HenryJS
Post Prodigy
Post Prodigy

IF date values in last week return 1

Hi all,

 

Please could you advise the DAX for below query

 

IF

  • EITHER: PlacementDate is in the last 7 days
  • OR ExtensionEndDate is in the last 7 days

 

THEN 1

 

ELSE 0

 

Filters.PNG

 

Thanks,

 

Henry

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Should work like this:


Column =
IF(
Table[Placementdate] >=TODAY() - 7 ||
Table[ExtensionEndDate ] >= TODAY - 7
1,
0
)



View solution in original post

Anonymous
Not applicable

Simply remove the equal operator from the second part of the two conditions, the ones that check that date is <=today. Just put inferior to today.

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Should work like this:


Column =
IF(
Table[Placementdate] >=TODAY() - 7 ||
Table[ExtensionEndDate ] >= TODAY - 7
1,
0
)



That only returns values that are both those statements

 

How do I return values

 

IF
Table[Placementdate] >=TODAY() - 7 
 
OR
 
Table[ExtensionEndDate ] >= TODAY - 7
Anonymous
Not applicable

The double pipe is equivalent to the OR operator. It should return 1 if either one of the mentioned conditions is true. Are you sure it's interpreting it as an AND condition? It would be very weird

Hi @Anonymous 

 

I can't work out why it's returning 1 for the below?

 

None of the dates are -7 from today?

 

Finishers.PNG

Anonymous
Not applicable

I'm sorry I didn't understand that you also had future Dates in the target columns. You need to modify the code in this way:

Column =
IF(
(Table[column1] >= TODAY() - 7 && Table[column1] <= TODAY()) ||
(Table[column2] >= TODAY() -7 && Table[column2] <= TODAY()),
1,
0
)

In this way it also checks that the "upper" limit of the two dates is today.

Thanks @Anonymous 

 

That's worked.

 

Last point - how can I ammend so it returns the last 7 days NOT including today?

 

Cheers,

 

Henry

Anonymous
Not applicable

Simply remove the equal operator from the second part of the two conditions, the ones that check that date is <=today. Just put inferior to today.

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.