The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello, I would like to color the bars in my bar chart accoring to the year on the x-axis:
The largest year (Max Year) should be red, second largest blue (Max Year -1) , third largest yellow (Max Year -2).
I am using a measure to calculate the colors which is working when I write down the years in the code but I would like to do it dynamically.
This is working:
Year Colour =
VAR MaxYear = MAX('Date'[Year])
VAR Color =
SWITCH (
True(),
MaxYear= 2023, "red",
MaxYear=2022, "blue",
MaxYear=2021, "yellow"
)
Return
color
But when I change it work dynamically all bars have the same color:
Year Colour =
VAR MaxYear = MAX('Date'[Year])
VAR MaxYearColour = MAX('Date'[Year])
VAR Color =
SWITCH (
True(),
MaxYear= MaxYearColour, "red",
MaxYear=2022, "blue",
MaxYear=2021, "yellow"
)
Return
color
Thank you very much for your help 🙂
Solved! Go to Solution.
Try:
Bar Colour =
VAR _YR =
MAXX ( ALLSELECTED ( 'Date'[Year] ), 'Date'[Year] )
VAR _YR1 =
MAXX ( EXCEPT ( ALLSELECTED ( 'Date'[Year] ), { _YR } ), 'Date'[Year] )
VAR _YR2 =
MAXX ( EXCEPT ( ALLSELECTED ( 'Date'[Year] ), { _YR, _YR1 } ), 'Date'[Year] )
RETURN
SWITCH (
SELECTEDVALUE ( 'Date'[Year] ),
_YR, "Red",
_YR1, "Blue",
_YR2, "Yellow"
)
Proud to be a Super User!
Paul on Linkedin.
Try:
Bar Colour =
VAR _YR =
MAXX ( ALLSELECTED ( 'Date'[Year] ), 'Date'[Year] )
VAR _YR1 =
MAXX ( EXCEPT ( ALLSELECTED ( 'Date'[Year] ), { _YR } ), 'Date'[Year] )
VAR _YR2 =
MAXX ( EXCEPT ( ALLSELECTED ( 'Date'[Year] ), { _YR, _YR1 } ), 'Date'[Year] )
RETURN
SWITCH (
SELECTEDVALUE ( 'Date'[Year] ),
_YR, "Red",
_YR1, "Blue",
_YR2, "Yellow"
)
Proud to be a Super User!
Paul on Linkedin.
Amazing it is working! Thank you very much!
User | Count |
---|---|
74 | |
70 | |
39 | |
30 | |
28 |
User | Count |
---|---|
104 | |
95 | |
51 | |
48 | |
46 |