Forum Discussion

kg_powerbi's avatar
kg_powerbi
Frequent Visitor
5 years ago
Solved

DateAdd and DatesMTD not working

Hello All, I am working on a measure that will return MTD sales for completed days in the month vs the same amount of days in the previous month.  For whatever reason if I use this formula it does...
  • Ashish_Mathur's avatar
    5 years ago

    Hi,

    To write a measure that will return MTD sales for completed days in the month vs the same amount of days in the previous month, you do not need to create another Date table.  Assuming you already have a Calendar table which only goes till the data till which there is sale, write these measures.

    Total sales = sum(data[sale])

    Total sales in same period last month = if(max(calendar[date])<eomonth(max(calendar[date]),0),calculate([total sales],datesbetween(calendar[date],edate(min(calendar[date]),-1),edate(max(calendar[date]),-1))),calculate([total sales],previousmonth(calendar[date])))

    To your visual/filters/slicers, drag date and other other date field (month/year) from the Calendar Table.