Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Using a date filter in CALCULATE

Hi all,
 
I am trying to use a measure to create a baseline calculation. Ideally it would automatically use the last full year of data (2018 for now) but I would be happy with it just being hard-set on 2018. The year right now is in a date heirarchy along with the month and day so I am a little unclear if it is possible to access this in a filter without copying the column in query editor and the separating it using commas.
 
Here's the formula I have now which is not returning anything.
2018 Baseline (QTY) = CALCULATE(AVERAGE('WEEKLY_VENDOR_PURCHASE'[QTY_RECEIVED]),DATESYTD('WEEKLY_VENDOR_PURCHASE'[DATE_RECEIVED].[Year]))
 
Thanks!

3 Replies

  • Anonymous for time intelligence calculations it is advised to have date calendar in your model and run all calculations from there. There are many posts to achieve this. For now, you can remove .year from your formula and see if it works.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks,

       

      I'll work on adding a date table, but for now I removed the .[YEAR] and got this error

       

      Error Message:
      MdxScript(Model) (9, 132) Calculation error in measure 'WEEKLY Tbl_MV_TM_VENDOR_PURCHASE'[2018 Baseline (QTY)]: A date column containing duplicate dates was specified in the call to function 'DATESYTD'. This is not supported.

       

      Is there another date/year function that would work better than DATESYTD?