Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

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?

 

 

  • Anonymous,

     

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

     

2 Replies

  • v-chuncz-msft's avatar
    v-chuncz-msft
    Community Support

    Anonymous,

     

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

     

    • Anonymous's avatar
      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