0
0
Power BIbi_tool~15 mins

SAMEPERIODLASTYEAR in Power BI - Real Business Scenario

Choose your learning style9 modes available
Scenario Mode
👤 Your Role: You are a sales analyst at a retail company.
📋 Request: Your manager wants to compare monthly sales this year with the same months last year to understand growth trends.
📊 Data: You have a sales dataset with columns: Date (daily), Sales Amount, and Product Category.
🎯 Deliverable: Create a report showing monthly sales for the current year and the same months last year side by side.
Progress0 / 8 steps
Sample Data
DateSales AmountProduct Category
2023-01-151000Electronics
2023-01-201500Furniture
2023-02-101200Electronics
2023-02-251300Furniture
2022-01-18900Electronics
2022-01-221100Furniture
2022-02-121000Electronics
2022-02-281200Furniture
2023-03-051400Electronics
2023-03-151600Furniture
2022-03-101300Electronics
2022-03-201500Furniture
1
Step 1: Create a Date table with continuous dates covering all sales dates.
Use Power BI's 'New Table' feature with formula: Date = CALENDAR(DATE(2022,1,1), DATE(2023,12,31))
Expected Result
A Date table with all dates from Jan 1, 2022 to Dec 31, 2023.
2
Step 2: Mark the Date table as a Date table in Power BI.
Select the Date table, then 'Mark as Date Table' and choose the Date column.
Expected Result
Power BI recognizes the Date table for time intelligence functions.
3
Step 3: Create a relationship between the Sales data Date column and the Date table Date column.
In Model view, drag Sales[Date] to Date[Date] to create a one-to-many relationship.
Expected Result
Sales data is connected to the Date table for filtering.
4
Step 4: Create a measure for Total Sales.
Total Sales = SUM('Sales'[Sales Amount])
Expected Result
A measure that sums all sales amounts.
5
Step 5: Create a measure for Sales Same Period Last Year using SAMEPERIODLASTYEAR function.
Sales LY = CALCULATE([Total Sales], SAMEPERIODLASTYEAR('Date'[Date]))
Expected Result
A measure that calculates sales for the same period last year.
6
Step 6: Create a matrix visual with rows as Year and Month from the Date table.
Add 'Date'[Year] and 'Date'[Month] to Rows in the matrix visual.
Expected Result
Matrix shows Year and Month as row headers.
7
Step 7: Add the Total Sales and Sales LY measures to the Values area of the matrix.
Drag 'Total Sales' and 'Sales LY' measures into Values.
Expected Result
Matrix shows sales for current year and same period last year side by side.
8
Step 8: Format the matrix to show sales amounts as currency and sort by Year then Month.
Use visual formatting pane to set currency format and sort order.
Expected Result
Matrix is easy to read with properly formatted sales values.
Final Result
Monthly Sales Comparison Report

Year  Month   Total Sales   Sales LY
2022  January  2000         -
      February 2200         -
      March    2800         -
2023  January  2500         2000
      February 2500         2200
      March    3000         2800
Sales increased in January 2023 compared to January 2022 by 500.
February 2023 sales also grew by 300 compared to last year.
March 2023 sales showed an increase of 200 compared to March 2022.
Bonus Challenge

Create a line chart showing monthly sales trends for current year and last year on the same graph.

Show Hint
Use the Date table's Month column on the X-axis and add both 'Total Sales' and 'Sales LY' measures as lines.