Forum Discussion

RodgerB's avatar
RodgerB
Frequent Visitor
6 years ago
Solved

Calculating YTD Sales using a Variable

Good afternoon, Team, I'm trying to do what should be a very simple thing.  Use variables in a CALCULATE for DATESYTD, and when I add it to a visual, it just shows the sum by row. My DAX is:  ...
  • mahoneypat's avatar
    6 years ago

    You should not calculate your expression first as a variable.  The way it is writtten, it is first doing the sum in the current context and then passing that as a fixed value into the Calculate() part.  Try this instead:

     

    YTD Sales = CALCULATE(SUM(Table[Sale AMT]), DATESYTD('Calendar'[Date']) //replace Table with the name of your table

     

    This assumes you are using columns from your 'Date' table in your visual.

     

    If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

    Regards,

    Pat