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
DBC01
New Member

Can anyone tell me why my If function is not working?

Hi Everyone,

 

New Power BI user here, dropped in at the deep end! I have a column within my table called 'last_service_date'. The data within it is formatted as Date/time. I'm have created a new column called 'Last week' with the goal of finding out which items have been serviced within the last seven days from todays date, using the following code:

 

 

last week = 
IF(
    DATEDIFF(MySheet[last_service_date], TODAY(), DAY) < 7,
    "Within last 7 days",
    "Not within last 7 days"
)

 

 

However, I am only recieving "Not within last 7 days" as my result, regardless of the the completion date of the service. Could anyone shine a light on where I have gone wrong? Thank you in advance! 🙂

1 ACCEPTED SOLUTION
PijushRoy
Super User
Super User

Hi @DBC01 

There is nothing wrong with the DAX, please see the SNAP below. Working as expected.

PijushRoy_0-1705668471619.png


Please check again the datatype of the date column and check if there is any data within the 7-day range.
Or increase the range 30days and check

View solution in original post

3 REPLIES 3
PijushRoy
Super User
Super User

Hi @DBC01 

There is nothing wrong with the DAX, please see the SNAP below. Working as expected.

PijushRoy_0-1705668471619.png


Please check again the datatype of the date column and check if there is any data within the 7-day range.
Or increase the range 30days and check

Thank you @PijushRoy . 

 

As I am clinically stupid I forgot that we are now in 2024 and not 2023! I've changed some dates around and the DAX works as expected.  

No Problem @DBC01 
You are welcome

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.