Bird
Raised Fist0
Power BIbi_tool~20 mins

SAMEPERIODLASTYEAR in Power BI - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of the SAMEPERIODLASTYEAR function in Power BI?
easy
A. To calculate the total sales for the current year
B. To compare data from the same period in the previous year
C. To filter data for the current month only
D. To create a new date column with next year's dates

Solution

  1. Step 1: Understand the function's purpose

    SAMEPERIODLASTYEAR shifts the date context back exactly one year to compare the same time periods.
  2. Step 2: Identify the correct use case

    It is used to compare measures like sales or revenue from this year to the same period last year.
  3. Final Answer:

    To compare data from the same period in the previous year -> Option B
  4. Quick Check:

    SAMEPERIODLASTYEAR compares last year's period [OK]
Hint: Think "same time last year" for comparison [OK]
Common Mistakes:
  • Confusing it with total aggregation functions
  • Using it to filter current year data
  • Assuming it creates future dates
2. Which of the following is the correct syntax to use SAMEPERIODLASTYEAR with a date column named Sales[Date]?
easy
A. SAMEPERIODLASTYEAR('Sales'[Date])
B. SAMEPERIODLASTYEAR(Sales[Date])
C. SAMEPERIODLASTYEAR(Sales.Date)
D. SAMEPERIODLASTYEAR([SalesDate])

Solution

  1. Step 1: Recognize correct table and column reference

    In DAX, table and column names are referenced as 'TableName'[ColumnName], so 'Sales'[Date] is correct.
  2. Step 2: Check syntax correctness

    SAMEPERIODLASTYEAR(Sales[Date]) omits single quotes around the table name. SAMEPERIODLASTYEAR(Sales.Date) uses invalid dot notation. SAMEPERIODLASTYEAR([SalesDate]) uses an incorrect column name format.
  3. Final Answer:

    SAMEPERIODLASTYEAR('Sales'[Date]) -> Option A
  4. Quick Check:

    Correct DAX column reference uses quotes and brackets [OK]
Hint: Use single quotes for table, brackets for column [OK]
Common Mistakes:
  • Omitting single quotes around table name
  • Using dot notation instead of brackets
  • Referencing columns without table name
3. Given the measure:
Sales LY = CALCULATE(SUM('Sales'[Amount]), SAMEPERIODLASTYEAR('Sales'[Date]))

If total sales for March 2023 are 1000, and for March 2022 are 800, what will Sales LY show when filtered on March 2023?
medium
A. 800
B. 1800
C. 1000
D. 0

Solution

  1. Step 1: Understand the measure calculation

    The measure sums sales amounts but shifts the date filter to the same period last year using SAMEPERIODLASTYEAR.
  2. Step 2: Apply the filter context for March 2023

    When filtered on March 2023, the measure returns sales from March 2022, which is 800.
  3. Final Answer:

    800 -> Option A
  4. Quick Check:

    Sales LY shows last year's same period sales [OK]
Hint: SAMEPERIODLASTYEAR shifts filter to last year [OK]
Common Mistakes:
  • Assuming it sums current year sales
  • Adding current and last year sales
  • Returning zero if no explicit filter
4. You wrote this measure:
Sales LY = CALCULATE(SUM('Sales'[Amount]), SAMEPERIODLASTYEAR(Sales[Date]))

But it returns an error. What is the likely cause?
medium
A. Measure name cannot contain spaces
B. SUM function cannot be used inside CALCULATE
C. SAMEPERIODLASTYEAR requires a numeric column
D. Missing single quotes around the table name 'Sales'

Solution

  1. Step 1: Check table and column references

    The table name 'Sales' must be enclosed in single quotes when referenced in DAX, so Sales[Date] is invalid.
  2. Step 2: Understand function requirements

    SUM inside CALCULATE is valid, SAMEPERIODLASTYEAR requires a date column, and measure names can have spaces.
  3. Final Answer:

    Missing single quotes around the table name 'Sales' -> Option D
  4. Quick Check:

    Table names need single quotes in DAX [OK]
Hint: Always quote table names in DAX formulas [OK]
Common Mistakes:
  • Forgetting single quotes around table names
  • Thinking SUM can't be inside CALCULATE
  • Assuming SAMEPERIODLASTYEAR needs numeric columns
5. You want to create a measure that shows the percentage change in sales compared to the same period last year. Which DAX formula correctly uses SAMEPERIODLASTYEAR to calculate this?
hard
A. Sales YoY % = CALCULATE(SUM('Sales'[Amount]), SAMEPERIODLASTYEAR('Sales'[Date])) - SUM('Sales'[Amount])
B. Sales YoY % = SUM('Sales'[Amount]) / SAMEPERIODLASTYEAR('Sales'[Date])
C. Sales YoY % = DIVIDE(SUM('Sales'[Amount]) - CALCULATE(SUM('Sales'[Amount]), SAMEPERIODLASTYEAR('Sales'[Date])), CALCULATE(SUM('Sales'[Amount]), SAMEPERIODLASTYEAR('Sales'[Date])))
D. Sales YoY % = SUM('Sales'[Amount]) - CALCULATE(SUM('Sales'[Amount]), SAMEPERIODLASTYEAR('Sales'[Date]))

Solution

  1. Step 1: Understand the percentage change formula

    Percentage change = (Current - Previous) / Previous, so we need current sales minus last year's sales divided by last year's sales.
  2. Step 2: Analyze each option

    Sales YoY % = DIVIDE(SUM('Sales'[Amount]) - CALCULATE(SUM('Sales'[Amount]), SAMEPERIODLASTYEAR('Sales'[Date])), CALCULATE(SUM('Sales'[Amount]), SAMEPERIODLASTYEAR('Sales'[Date]))) correctly uses DIVIDE to avoid errors and calculates the difference over last year's sales. Sales YoY % = SUM('Sales'[Amount]) / SAMEPERIODLASTYEAR('Sales'[Date]) divides sales by a date column, which is invalid. Sales YoY % = CALCULATE(SUM('Sales'[Amount]), SAMEPERIODLASTYEAR('Sales'[Date])) - SUM('Sales'[Amount]) subtracts current from last year without division. Sales YoY % = SUM('Sales'[Amount]) - CALCULATE(SUM('Sales'[Amount]), SAMEPERIODLASTYEAR('Sales'[Date])) calculates difference but not percentage.
  3. Final Answer:

    Sales YoY % = DIVIDE(SUM('Sales'[Amount]) - CALCULATE(SUM('Sales'[Amount]), SAMEPERIODLASTYEAR('Sales'[Date])), CALCULATE(SUM('Sales'[Amount]), SAMEPERIODLASTYEAR('Sales'[Date]))) -> Option C
  4. Quick Check:

    Percentage change = (Current - LastYear) / LastYear [OK]
Hint: Use DIVIDE for safe percentage calculations [OK]
Common Mistakes:
  • Dividing by a date column instead of sales
  • Forgetting to divide difference by last year's sales
  • Subtracting without calculating percentage
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard