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?
Remember, SAMEPERIODLASTYEAR expects a date column as its argument.
Option A correctly uses SAMEPERIODLASTYEAR with the Date column to shift the filter context to the same period last year. Option A uses PREVIOUSYEAR, which returns the entire previous year, not the same period. Option A uses DATEADD which can work but is not the same function. Option A incorrectly passes a numeric column to SAMEPERIODLASTYEAR, causing an error.
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?
Think about how to compare two measures over time on the same chart.
Option D correctly uses the Date column at the month level on the axis and uses the measure names as legend to compare current and last year sales. Option D incorrectly uses SalesAmount on axis which is a value, not a time. Option D uses year level which is too coarse for monthly comparison. Option D uses Date for both axis and legend which does not separate the measures.
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?
Think about how SAMEPERIODLASTYEAR shifts the current filter context.
SAMEPERIODLASTYEAR returns the equivalent period last year based on the current filter context. Since the filter is March 2023, it returns March 2022 dates only. It does not return the entire year or unrelated dates.
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?
Check the model setup for time intelligence functions.
Time intelligence functions like SAMEPERIODLASTYEAR require the date table to be marked as a Date table in Power BI. Without this, the function returns blank. Option A might cause low values but not necessarily blank. Option A is incorrect because SAMEPERIODLASTYEAR requires a date column. Option A is not necessary here.
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?
Remember how to apply multiple filters inside CALCULATE.
Option B correctly applies the time filter with SAMEPERIODLASTYEAR and the category filter using FILTER on the Products table. Option B tries to filter by category directly which works only if the column is a simple filter, but best practice is to use FILTER for table filters. Option B uses FILTER incorrectly on a date table. Option B uses invalid syntax combining filters with && inside CALCULATE.