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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
DBC01
Regular Visitor

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




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





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




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





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




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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