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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Jaqinthebox
Regular Visitor

Conditional formatting using a measure

Hi,

 

How can I have different colours for different years in a chart visual? I have tried a switch measure but when I go to the Conditional formatting option on the visual, the measure I just made does not load, I just get a "blank" red outlined box;

 

Jaqinthebox_1-1715619204432.png

 

 

Jaqinthebox_0-1715618958988.png

The calculation I used for the measure was;

Colour scheme = SWITCH(true(), max('Calendar'[Year])="2022","pink",

max('Calendar'[Year])="2023", "purple",

max('Calendar'[Year])="2024", "orange","silver")

 

Or am I going about this the wrong way?

 

Thank you in advance.

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but if the year column in the calendar table is not text format, please try something like below.

 

Colour scheme =
SWITCH (
    TRUE (),
    MAX ( 'Calendar'[Year] ) = 2022, "pink",
    MAX ( 'Calendar'[Year] ) = 2023, "purple",
    MAX ( 'Calendar'[Year] ) = 2024, "orange",
    "silver"
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

4 REPLIES 4
v-xiandat-msft
Community Support
Community Support

Hi @Jaqinthebox ,

Thank you for @Jihwan_Kim and @_AAndrade answer , and I have other suggestions:
Below is my table:

vxiandatmsft_0-1715649313192.png

The following DAX might work for you:

Colour scheme = 
SWITCH(true(), 
MAX('Table'[Date]) = "1/1/2024","pink",

MAX('Table'[Date])="2/1/2024", "purple",

MAX('Table'[Date])="3/1/2024", "orange","silver")

The final output is shown in the following figure:

vxiandatmsft_1-1715649879865.png

vxiandatmsft_2-1715649999568.png

 

What we can see is that this metric is applied well in the table, indicating that there is no problem, on the bar chart the x-axis fails, which is an existing problem.

There is currently no way to control the x-axis of the bars via measure.

Best Regards,

Xianda Tang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you all for your replies @v-xiandat-msft @Jihwan_Kim @_AAndrade 

 

It was the reply from @Jihwan_Kim which helped. I hadn't formatted the "Year" column in my calendar to Text. I had no idea that had to be done for conditional formatting measures to work (I'm relatively new to Power BI!)

 

Result as below;

 

Jaqinthebox_0-1715673979372.png

 

Thanks again to everyone that replied.

 

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but if the year column in the calendar table is not text format, please try something like below.

 

Colour scheme =
SWITCH (
    TRUE (),
    MAX ( 'Calendar'[Year] ) = 2022, "pink",
    MAX ( 'Calendar'[Year] ) = 2023, "purple",
    MAX ( 'Calendar'[Year] ) = 2024, "orange",
    "silver"
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


_AAndrade
Super User
Super User

Did you try to click on that box and search for your measure?





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.