0
0
Power BIbi_tool~10 mins

SAMEPERIODLASTYEAR in Power BI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate sales for the same period last year.

Power BI
Sales LY = CALCULATE(SUM(Sales[Amount]), SAMEPERIODLASTYEAR([1]))
Drag options to blanks, or click blank then click option'
ASales[Amount]
BCalendar[Date]
CSales[Date]
DCalendar[Year]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-date column inside SAMEPERIODLASTYEAR.
Using the sales amount column instead of a date column.
2fill in blank
medium

Complete the code to calculate last year's sales filtered by product category.

Power BI
Sales LY Category = CALCULATE(SUM(Sales[Amount]), SAMEPERIODLASTYEAR([1]), FILTER(Products, Products[Category] = "Bikes"))
Drag options to blanks, or click blank then click option'
ASales[Date]
BProducts[Category]
CCalendar[Date]
DSales[Category]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a category column inside SAMEPERIODLASTYEAR.
Confusing the filter context with the date argument.
3fill in blank
hard

Fix the error in the code to correctly calculate sales for the same period last year.

Power BI
Sales LY = CALCULATE(SUM(Sales[Amount]), SAMEPERIODLASTYEAR([1]))
Drag options to blanks, or click blank then click option'
ACalendar[Date]
BProducts[Date]
CSales[Date]
DSales[Amount]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a measure or amount column instead of a date column.
Using a date column from a fact table instead of a calendar table.
4fill in blank
hard

Fill both blanks to calculate last year's sales for a selected month and year.

Power BI
Sales LY Selected = CALCULATE(SUM(Sales[Amount]), SAMEPERIODLASTYEAR([1]), FILTER(ALL(Calendar), Calendar[Month] = [2]))
Drag options to blanks, or click blank then click option'
ACalendar[Date]
BCalendar[Month]
C"January"
DSales[Month]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-date column in SAMEPERIODLASTYEAR.
Using a column name instead of a string for the month filter.
5fill in blank
hard

Fill all three blanks to calculate last year's sales filtered by year and product color.

Power BI
Sales LY Filtered = CALCULATE(SUM(Sales[Amount]), SAMEPERIODLASTYEAR([1]), FILTER(ALL(Calendar), Calendar[Year] = [2]), FILTER(Products, Products[Color] = [3]))
Drag options to blanks, or click blank then click option'
ACalendar[Date]
B2022
C"Red"
DSales[Year]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a fact table column instead of calendar date.
Using strings instead of numbers for year filter or vice versa.
Not quoting the color string.