Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Power BI Total

Hi, I have created measures for Current Year Sales vs Last Year Sales.  For Current Year: CY Sales = SUM(sales[subtotal])   For Last Year: LY Sales = CALCULATE([Sales], 'sales'[Year] = S...
  • v-chenwuz-msft's avatar
    v-chenwuz-msft
    4 years ago

    Hi Anonymous  , 

    Every row has context for measure to calculate. So, we should modify the context via filter(all(table)....). at this point, we need condsider each month but also the total row. So get a range date of current row. For example, month 1 year 2021 , the start date of last year is date(2021 -1 ,1,1), the end date is date(2021-1,1,31). This is what var _start and var _end do.

     

    But if your "startdate" type is Date, maybe you can try this code:

    LY sales = CALCULATE(SUM('Table'[Sales]),all(),DATEADD('Table'[Date],-1,YEAR))​

    result:

     

    You can refer the pbix in the attachment. if you need more help, please share your pbix file without sensitive date.

     

    Best Regards

    Community Support Team _ chenwu zhu

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.