98.8% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Power BI training and help » DAX Measure SAMEPERIODLASTYEAR
DAX Measure SAMEPERIODLASTYEAR
Resolved · Medium Priority · Version 365
Adam has attended:
Power BI DAX course
DAX Measure SAMEPERIODLASTYEAR
Hi,
I've got a simple dataset that has a main data table (composite) and a dynamic dates table, which has a many to one relationship.
I'm trying to build two measures for the same KPI, one for current and year and other for last year.
My two measures are returning the same result though and I cannot see why :( what am I missing?
Absorption CY:
Aftersales Absorption CY =
var CurrentYear = YEAR(TODAY())
var Absorption =
DIVIDE(
SUM(Composite[Service Direct Profit]) + SUM(Composite[Parts Direct Profit]),
SUM(Composite[Total Overheads]))
var AbsorptionCY = CALCULATE(Absorption, Dates[Year] = CurrentYear)
return
AbsorptionCY
Absorption PY:
Aftersales Absorption PY =
VAR Absorption =
DIVIDE (
SUM(Composite[Service Direct Profit]) + SUM(Composite[Parts Direct Profit]),
SUM(Composite[Total Overheads])
)
VAR AbsorptionPY =
CALCULATE (Absorption, SAMEPERIODLASTYEAR(Dates[Date]))
RETURN
AbsorptionPY
Also, I'll use SUMX once I've worked out whats going wrong here.
RE: DAX Measure SAMEPERIODLASTYEAR
Hi Adam,
Thank you for the forum question.
It looks like you're on the right track with your DAX measures, but there are a couple of things that might be causing them to return the same results. Let's break it down:
1. Measure Calculation Context
Both measures are calculating the same base Absorption value, which is defined as:
DIVIDE(
SUM(Composite[Service Direct Profit]) + SUM(Composite[Parts Direct Profit]),
SUM(Composite[Total Overheads])
)
This means that if the context in which these measures are evaluated is the same, they will yield the same result.
2. Filtering by Year
Current Year Measure:
var AbsorptionCY = CALCULATE(Absorption, Dates[Year] = CurrentYear)
This correctly filters the data for the current year.
Previous Year Measure:
VAR AbsorptionPY = CALCULATE(Absorption, SAMEPERIODLASTYEAR(Dates[Date]))
This should also filter the data for the previous year.
3. Potential Issues
Date Table Configuration: Ensure that your Dates table is properly configured with continuous dates and that the relationship with the Composite table is set correctly. If the relationship is not active or if there are issues with the date values, it could lead to unexpected results.
Data Context: If both measures are being evaluated in the same visual context (e.g., the same date filter), they might return the same value. Try placing them in different visuals or using slicers to isolate the years.
4. Revised Measures
You might want to explicitly define the context for each measure. Here’s a refined version:
Aftersales Absorption CY =
VAR CurrentYear = YEAR(TODAY())
VAR Absorption =
DIVIDE(
SUM(Composite[Service Direct Profit]) + SUM(Composite[Parts Direct Profit]),
SUM(Composite[Total Overheads])
)
RETURN
CALCULATE(Absorption, Dates[Year] = CurrentYear)
Aftersales Absorption PY =
VAR Absorption =
DIVIDE(
SUM(Composite[Service Direct Profit]) + SUM(Composite[Parts Direct Profit]),
SUM(Composite[Total Overheads])
)
RETURN
CALCULATE(Absorption, SAMEPERIODLASTYEAR(Dates[Date]))
5. Testing
Check Results: After making these adjustments, test the measures in a visual with a date filter to see if they return different values.
Debugging: You can also create a simple card visual for each measure to see their outputs independently.
If you still encounter issues, feel free to share more details about your data model or any specific errors you're facing!
Kind regards
Jens Bonde
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Power BI tip:Explore Power BI TemplatesTake advantage of Power BI templates to streamline report creation. Templates allow you to reuse custom layouts, themes, and configurations across multiple reports. Create templates for consistent branding or industry-specific reporting standards, saving time and maintaining a cohesive look across your organization's reports. |