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
Anonymous
Not applicable

Calculating Last Week using DATEADD not performing as expected

I have a series of KPIs that I display in a table side by side for each location within the business.

 

I want to add the last week performance of each KPI to the table along side the current week. However using DATEADD doesn't appear to change the output. 

I'm using a page level filter to slice the data to the last 7 days in the table.

 

As you can see below the output of [LW KPI 1] is the same as the measure it directly references. The DAX in use is:

 

 

LW KPI 1 % Jobs Completed on Time = CALCULATE([KPI 1 % Jobs Completed on Time], DATEADD(Jobs[Date Range
Jobs].[Date], -7, DAY))

 

Any idea why the DATEADD filter is being ignored?

Last Week not working edit.png

 

 

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@Anonymous,

 

It might be caused by date hierarchy. Try to remove .[Date] from the formula above.

 

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-chuncz-msft
Community Support
Community Support

@Anonymous,

 

It might be caused by date hierarchy. Try to remove .[Date] from the formula above.

 

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Sorry I did reply to this, but it doesn't appear to have posted.

 

Removing .[date] hierarchy introduces a duplicate values error for DATEADD.

 

So I wrote the following, using the VALUES function to give me a distinct list of dates for each DATEADD function, but get the same duplicates error.

 

Any ideas?

 

KPI Score Last Week = 

var Dates = VALUES(Reports[Date Range])

var KPI1LW = CALCULATE([KPI 1 %], DATEADD(Dates,-7, DAY))
var KPI2LW = CALCULATE([KPI 2 %], DATEADD(Dates, -7, DAY))
var KPI3LW = CALCULATE([KPI 3 %],DATEADD(Dates, -7, DAY))
var KPI4LW = CALCULATE([KPI 4 %],DATEADD(Dates, -7, DAY))

VAR KPI1Score = IF(KPI1LW > [KPI 1 Target], 1, 0)
VAR KPI2Score = IF(KPI2LW > [KPI 2 Target], 1, 0)
VAR KPI3Score = IF(KPI3LW > [KPI 3 Target], 1, 0)
VAR KPI4Score = IF(KPI4LW > [KPI 4 Target], 1, 0)

RETURN
KPI1Score + KPI2Score + KPI3Score + KPI4Score

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.