Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
sivarajan21
Post Patron
Post Patron

Create a dax for legend to show color difference and label them

Hi Team,

 

I have this below visual :

sivarajan21_0-1730795513332.png

Blue color bars are current temperature. I want to show bar in different colors(cool=blue, orange=heat, green=fan) from which Usermode this comes from.

sivarajan21_1-1730796048749.png

 

I don't want to drag this user mode column into the legend field as that will show every fields in legend as below:

sivarajan21_2-1730796231473.png

legend should only display current temperature, Average site temp, set point temp, fan speed. 

User mode should be displayed in different colors for current temp bars and even a data label to show as usermode as heat,auto,cool etc.

 

Please advise!

PFA file here Heatsense - Copy - Copy.pbix

 

Thanks in advance!

@marcorusso @Jihwan_Kim @Greg_Deckler @amitchandak @Ahmedx 

 

8 REPLIES 8
PhilipTreacy
Super User
Super User

Hi @sivarajan21 

 

When you remove DeviceID from the X axis the CF will stop working, it's dependent on DeviceID being on the X axis.

 

With you have a date column on the x axis, how do you know what UserMode to use?  There are multiple UserModes for each date.

 

The labels on the visual are for the numeric data values, you already have the DeviceID's shown on the x axis.

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi @PhilipTreacy ,

 

Thanks for your quick response!

Apologise for the delay in response and we tested on it.

Agree with your point! but we have to select user mode where iscurrent column is 1.

For example, Below is the visual where deviceid selected is B0965C2B9CF2A6C855A3C245F6B72F1A:

sivarajan21_0-1731348349191.png

The color of the current temp should vary according to the user mode where iscurrent is 1. Therefore in this case, usermode is auto

sivarajan21_1-1731348933957.png

So color should be grey. your below measure is useful but i am confused how to apply them for above visual when updatedon date column is in x-axis.

Column Color = 

VAR _UserMode = SELECTEDVALUE('HeatSense_Device'[UserMode])

RETURN 

SWITCH(

    TRUE(),

    _UserMode = "cool", "#12239E",

    _UserMode = "heat", "#FF8C00",

    _UserMode = "fan", "green",

    "#808080"

)

 

Please advise!

PFA file here Heatsense - Copy - Copy.pbix

 

Thanks in advance!
@marcorusso @Greg_Deckler @PhilipTreacy @lbendlin @Jihwan_Kim @Ahmedx @v-linyulu-msft @v-yaningy-msft 

lbendlin
Super User
Super User

Hide the legend?

 

lbendlin_0-1730810215675.png

 

Hi @lbendlin ,

 

Apologise for not being clear!

We need the legend for current temp, setpoint temp, fan speed & average temp except user mode.

User mode should be reflected on bars in different colors and their respective labels marking them as Orange for heat, Blue for cool, pink for fan and grey for auto.

@PhilipTreacy  answer is got it correct but we wanted it to work when Date column is in x-axis.

 

Thanks in advance!

saud968
Solution Sage
Solution Sage

First, create a measure for color-coding based on Usermode:

daxCopyColorByUsermode =
SWITCH(
VALUES(Table[Usermode]),
"cool", "#0066CC", // Blue
"heat", "#FF6600", // Orange
"fan", "#33CC33", // Green
"#0066CC" // Default blue
)

Create a measure for the legend labels:

daxCopyLegendLabel =
VAR CurrentMode = VALUES(Table[Usermode])
RETURN
SWITCH(
TRUE(),
SELECTEDVALUE(Table[Measure]) = "Current Temperature",
"Current Temp (" & CurrentMode & ")",
SELECTEDVALUE(Table[Measure]) = "Average Site Temperature",
"Avg Site Temp",
SELECTEDVALUE(Table[Measure]) = "Set Point Temperature",
"Set Point Temp",
SELECTEDVALUE(Table[Measure]) = "Fan Speed",
"Fan Speed",
"Other"
)
Then to implement this:

Remove the Usermode from the legend field
In the format pane:

Use the ColorByUsermode measure for the bar colors
Use the LegendLabel measure for the legend text


Add a data label to show the Usermode text on the bars

Best Regards
Saud Ansari
If this post helps, please Accept it as a Solution to help other members find it. I appreciate your Kudos!

Hi @saud968 ,

 

Error in your measure

sivarajan21_1-1730830848434.png

 

 

Thanks

PhilipTreacy
Super User
Super User

Hi @sivarajan21 

 

Here's your file with the code below in it

 

Write this DAX which sets the color for the columns

 

 

Column Color = 

VAR _UserMode = SELECTEDVALUE('HeatSense_Device'[UserMode])

RETURN 

SWITCH(

    TRUE(),

    _UserMode = "cool", "blue",

    _UserMode = "heat", "orange",

    _UserMode = "fan", "green",

    "grey"

)

 

 

Then apply that as a Conditional Formatting rule

 

PhilipTreacy_0-1730809576028.png

 

PhilipTreacy_1-1730809591163.png

 

PhilipTreacy_2-1730809606464.png

 

Note that the grey columns don't have an associated UserMode, hence they are grey.

 

Regards

 

Phil

 

 

 

 

 

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi Phil,

Thanks for your quick response!

Your dax is perfect and works when deviceid is on X-axis. 

But when I dragged UpdatedOn date column from Heatsense Device table into x-axis different colors doesn't work:

sivarajan21_0-1730830055264.png

Also, is it possible to label them as cool, heat, fan on their respective colors?

 

Please advise!

PFA updated file here Heatsense - Copy - Copy.pbix

 

Thanks in advance!

@PhilipTreacy @lbendlin @saud968 @marcorusso @Greg_Deckler @Ahmedx @Jihwan_Kim 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.