0
0
Power BIbi_tool~20 mins

SAMEPERIODLASTYEAR in Power BI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SAMEPERIODLASTYEAR Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
dax_lod_result
intermediate
2:00remaining
Calculate Sales for Same Period Last Year

You have a Sales table with a Date column and a SalesAmount column. You want to create a measure that calculates the total sales for the same period last year using the SAMEPERIODLASTYEAR function.

Which of the following DAX measures will correctly calculate this?

ASales LY = CALCULATE(SUM(Sales[SalesAmount]), SAMEPERIODLASTYEAR(Sales[Date]))
BSales LY = CALCULATE(SUM(Sales[SalesAmount]), PREVIOUSYEAR(Sales[Date]))
CSales LY = CALCULATE(SUM(Sales[SalesAmount]), DATEADD(Sales[Date], -1, YEAR))
DSales LY = CALCULATE(SUM(Sales[SalesAmount]), SAMEPERIODLASTYEAR(Sales[SalesAmount]))
Attempts:
2 left
💡 Hint

Remember, SAMEPERIODLASTYEAR expects a date column as its argument.

visualization
intermediate
2:00remaining
Visualizing Sales with SAMEPERIODLASTYEAR

You created two measures: Sales and Sales LY using SAMEPERIODLASTYEAR. You want to show a line chart comparing monthly sales this year and last year.

Which of the following is the best practice for the axis and legend setup in Power BI?

AAxis: Sales[Date] (month level), Legend: Sales[Date]
BAxis: Sales[SalesAmount], Legend: Sales[Date]
CAxis: Sales[Date] (year level), Legend: Measure (Sales, Sales LY)
DAxis: Sales[Date] (month level), Legend: Measure (Sales, Sales LY)
Attempts:
2 left
💡 Hint

Think about how to compare two measures over time on the same chart.

🧠 Conceptual
advanced
2:00remaining
Understanding SAMEPERIODLASTYEAR Behavior with Filter Context

Consider a report page filtered to show data only for March 2023. You use a measure with SAMEPERIODLASTYEAR on the Date column.

What period will the SAMEPERIODLASTYEAR function return in this filter context?

AAll dates in the Sales table
BThe entire year of 2022
CThe dates for March 2022 only
DThe dates for March 2023 only
Attempts:
2 left
💡 Hint

Think about how SAMEPERIODLASTYEAR shifts the current filter context.

🔧 Formula Fix
advanced
2:00remaining
Debugging a Measure Using SAMEPERIODLASTYEAR

A user wrote this measure but it returns blank values:

Sales LY = CALCULATE(SUM(Sales[SalesAmount]), SAMEPERIODLASTYEAR(Calendar[Date]))

Assuming the Sales table and Calendar table are related by Date, what is the most likely reason for the blank result?

AThe Calendar table is not marked as a Date table in the model
BThe Sales[SalesAmount] column contains only zeros
CThe SAMEPERIODLASTYEAR function requires a numeric column, not a date column
DThe measure should use FILTER instead of CALCULATE
Attempts:
2 left
💡 Hint

Check the model setup for time intelligence functions.

🎯 Scenario
expert
3:00remaining
Advanced Scenario: Combining SAMEPERIODLASTYEAR with Multiple Filters

You want to create a measure that calculates sales for the same period last year but only for products in the 'Electronics' category. The Sales table has a relationship to the Products table.

Which of the following DAX measures will correctly calculate this?

ASales LY Electronics = CALCULATE(SUM(Sales[SalesAmount]), FILTER(SAMEPERIODLASTYEAR(Calendar[Date]), Products[Category] = "Electronics"))
BSales LY Electronics = CALCULATE(SUM(Sales[SalesAmount]), SAMEPERIODLASTYEAR(Calendar[Date]), FILTER(Products, Products[Category] = "Electronics"))
CSales LY Electronics = CALCULATE(SUM(Sales[SalesAmount]), SAMEPERIODLASTYEAR(Calendar[Date]) && Products[Category] = "Electronics")
DSales LY Electronics = CALCULATE(SUM(Sales[SalesAmount]), SAMEPERIODLASTYEAR(Calendar[Date]), Products[Category] = "Electronics")
Attempts:
2 left
💡 Hint

Remember how to apply multiple filters inside CALCULATE.