DAX Workout 002 - Highlight Color Bars

@mbraun ,

Yup. We draw workouts from a wide range of sources. Some are specific issues that the Workout Leaders have encountered in their own work, and at times we will also adapt workouts that we think have broad applicability from forums, Accelerator courses, presentations, challenges - you name it…

We’re also wide open to input from the Community. If you have a good problem you’ve encountered in your own work that you think would make a good workout, definitely send it along to me and/or the workout leader(s).

Thanks!

  • Brian
3 Likes

Are you suggesting using colour names just from a readability point of view in your DAX or is there any difference in performance?

1 Like

No difference in performance. It’s really just a readability viewpoint. Not many people know what #EFEF66 color is but they will understand Soft yellow when selecting the color

Paul

2 Likes

@AntonyC you could always do this but wouldn’t be necessary. Just showing you options

1 Like

Hello friends, my first workout! I am pleased to share the solution, also as @BrianJ keeping gray all three years gray when no year is selected
SWITCH Color =

VAR SelCol = SELECTEDVALUE(Colores[Color])

VAR SelYear = SELECTEDVALUE(Dates[Year])

VAR Slicer = VALUES(‘Seleccion Año’[Year])

VAR Color = IF(AND(SelYear IN Slicer, ISFILTERED(‘Seleccion Año’[Year])), SelCol, “DimGray”)

Return

Color
DAX Workout No2 032323LG.pbix (506.0 KB)

2 Likes

Good job @LuisGonzalez

1 Like

@Paul.Gerber thanks for a great workout. I must admit to getting stuck on this one so I ended up using the solutions from @DavieJoe & @BrianJ :pray: :pray: :pray: I haven’t worked much with disconnected tables so it was a good learning exercise

2 Likes

Hi @KimC thanks for name checking, nice to know my solution, along with @BrianJ helped you along the way.

1 Like

@KimC I’m happy that you enjoyed the workout. See you on the next one.

1 Like

This workout topic wasn’t familiar to me, so I learned many things while doing it. I started by entering some color data manually. I got the color names from @BrianJ 's lovely “Cheatsheet”, thanks for that!

image

Then I created a new “Years” table without connecting it to anywhere.

Years = DISTINCT(Dates[Year])

And then I created the following measure (again utilising the Cheatsheet):

Color measure = 
VAR _color = SELECTEDVALUE(Colors[Colorname], "DarkGrey")
VAR _year = VALUES(Years[Year])

RETURN
IF(
    AND(
        ISFILTERED(Years[Year]), SELECTEDVALUE(Dates[Year]) IN _year
    ), _color, "LightGrey"
)

I got the idea of the “default” colors from here as well, good additions I think, so thanks to you all who contributed to this topic! :hugs:

And finally I inserted the column chart, and changed the Format style of the columns to be “Field value” / “Color measure”.

2 Likes

Great Job to everyone on this workout. Here is my solution and approach.

First I created a table for the colors I wanted.

image

Then a table for the Years only which is a disconnected table.

image

Then last, my measure for the changing the color of my bar graph.

image

Set up the visuals:

Go to format and choose Field Values

I hope you enjoyed the Workout!

All the best,

Paul

1 Like

DAX Workout No2 032323 practice.pbix (505.2 KB)

2 Likes

Good job @abbi glad you enjoyed the workout

Paul

1 Like

image

This much I can think for the simplest solution

Highlight sales year =
VAR Color_sel =
SELECTEDVALUE(
‘Choose color to highlight’[Choose Highlight Color]
)
VAR Year_Sel =
VALUES(
‘Choose years to highlight’[Select Years to Highlight]
)
RETURN
IF(
MAX(
Dates[Year]
)
in
Year_Sel,
Color_sel,
“grey”
)

2 Likes

Good job! Good to see you do a workout @shahadathossen.shajj

1 Like

Here is my submission for this workout, with the measures I created.
Thanks Enterprise DNA for these amazing DAX workouts.

1 Like

This is awesome

1 Like

1 Like

answer:
solution:


DAX Workout No6 MB.pbix (1.3 MB)

1 Like

Creating two disconnected tables (DimensionYear, Highlight Color)

ColoresDimensión = 
    VAR ColorSeleccionado =SELECTEDVALUE('Highlight Color'[Hex])  -- Color Hexadecimal selecionado en dimensión
    VAR anoSeleccionado = VALUES(Dates[Year])   
    VAR Resultado = IF(
                    iSFILTERED(DimensionYear) && anoSeleccionado in VALUES(DimensionYear[Year]),
                    ColorSeleccionado,
                    "#0070BB" ) -- color azul
        RETURN
            Resultado

Captura de pantalla 2024-01-19 110959

1 Like