DAX-SAMEPERIODLASTYEAR (COMPARE CURRENT YEAR WITH PREVIOUS YEAR SALES)
Today’s post is about how you compare Current year and Previous year sales using DAX- SAMEPERIODLASTYEAR function in Power BI.
SAMEPERIODLASTYEAR Returns a table that contains a column of dates shifted one year back in time from the dates in the specified dates column, in the current context.
1. We will start by creating a Date table using the “New Table” option under Modeling.
CALENDAR(<start_date>, <end_date>)
- Set the start date to go back one year before the current date
- Set the end date to TODAY() to display only values up to the current date.
MyDate=CALENDAR(TODAY()-365, TODAY())
2. Ensure that relationships are set in the model and now create a table visual with Sales for 2018 and 2019.
3. To compare the sales for 2018 to 2019 Month by month or day by day, we create a DAX measure using SAMEPERIODLASTYEAR to display last year sales.
SALES LY =
CALCULATE(SUM(Sales[SalesAmount]), SAMEPERIODLASTYEAR(Sales[Date]))
4. Create a table visual that compare sales for 2018 and 2019.
5. Filter by Current year (2019) to see the current and previous year sales side by side.
Happy reporting 🙂