Forum Discussion
Conditional Format Column Chart to compare Latest Year with Previous Year
- Anonymous2 years ago
Hi smallfires0628 ,
I did a simple test and you can create something like the following measure applied in conditional formatting. The reference is below:
M_ = VAR this_year = CALCULATE ( SUM ( 'Table'[Value] ) ) VAR last_year = CALCULATE ( SUM ( 'Table'[Value] ), SAMEPERIODLASTYEAR ( 'Date'[Date] ) ) RETURN IF ( this_year > last_year, "Red", "Green" )Best Regards,
Adamk KongIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
I tried something like this:
My reasoning for this code was something along these lines:
My column chart has an x-axis with a hierarchy of Month, then year. So I am thinking that my total bookings will be filtered by month first, then year.
So to calculate the latest year bookings for each month, I would simply have to use the function ALLSELECTED, which from my understanding, keeps the filters from outside. So that means, total bookings in this case will still be filtered by month first, then by year. So to get the total bookings for 2023 for jan, I would simply have to apply max function to YEAR('Calendar Table'date). Similarly for previous year, I'll do the same but just subtract 1 to get total bookings for 2022 for jan.
And with that out of the way, I'll just use the IF function to apply the right conditional formatting.
Is this reasoning flawed? I am quite new to dax, so I still don't understand how PowerBI filters work.