Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hello,
My measure for "Change from PY" is not correct for some records for 2021 and 2022. For example: Apple, Full, 2022, Change should be -9. Pear, Part, 2021, Change should be -1. Pear, Full, 2022, Change should be -10.
What is wrong with my current DAX code? I created a Calendar table and connected 'Calendar'[Year] to 'Sheet1'[Year].
Calendar = CALENDAR(DATE(2020,1,1),DATE(2022,12,31))
Year = YEAR('Calendar'[Date])
newCount = CALCULATE(SUM(Sheet1[Count]))+0
Change from PY =
VAR
vCY = MAX('Calendar'[Year])
VAR vPYAmount =
CALCULATE([newCount],'Calendar'[Year]=vCY - 1)
VAR vCYAmount =
CALCULATE([newCount])
VAR Result =
vCYAmount - vPYAmount
RETURN Result
Group | Type | Metric | Count | Year |
A | Apple | Full | 5 | 2020 |
A | Apple | Full | 9 | 2021 |
A | Apple | Part | 2 | 2022 |
B | Pear | Part | 1 | 2020 |
B | Pear | Full | 10 | 2021 |
Solved! Go to Solution.
Hi @dragon2
The DAX isn't the issue..
The problem is with your many-to-many relationship on [Year].
Instead I created a caculated column on your Sheet1 table: Date = DATE( [Year], 1, 1 )
Hi, @gmsamborn
Using your sample data as a reference, I created a simple table. Then, to generate the column you need, I added a calculated column using the following formula:
I believe this should give you exactly what you were looking for.
If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it!
Thank you.
Hi @dragon2
The DAX isn't the issue..
The problem is with your many-to-many relationship on [Year].
Instead I created a caculated column on your Sheet1 table: Date = DATE( [Year], 1, 1 )
Thank you so much.
For some reason, with my acutal data, this was not working. So, instead of making the Calendar table that I shared originally, I made a new table like this:
newCalendar = DISTINCT(Sheet1[Year])
Then I made a 1-to-many relationship on this table and sheet1[Year]. It worked perfectly after that.
User | Count |
---|---|
85 | |
79 | |
64 | |
52 | |
46 |
User | Count |
---|---|
101 | |
44 | |
41 | |
39 | |
36 |