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
admin11
Memorable Member
Memorable Member

How to make Qtr Bar chart all Q1 same color and Q2 same color.

Hi All

 

I have a Qtr bar chart , i like to make all Q1 bar same color . i have try measure  , i get error :-


color by qtr = Switch(max('Date'[year]),
Q1, "green",
Q2, "blue",
Q3, "red",
Q4"grey"
)

 

admin11_0-1616919166154.png

My PBI file :-

 

https://www.dropbox.com/s/bcxgotj4edvdtqe/PBT_V2021_392%20TI_SI_GL%20Qtr%20Q1%20bar%20all%20same%20c...

 

Paul

2 ACCEPTED SOLUTIONS
PhilipTreacy
Super User
Super User

@admin11 

Hi Paul,

 

Download PBIX

 

This code works

 

 

color by qtr = 

VAR __Qtr = SELECTEDVALUE('Date'[Year Quarter])

RETURN

SWITCH(
    
    TRUE(),
    

    CONTAINSSTRING(__Qtr, "Q1"), "green",

    CONTAINSSTRING(__Qtr, "Q2"), "blue",

    CONTAINSSTRING(__Qtr, "Q3"), "red",

    "gray"
)

 

 

colbars.png

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!


View solution in original post

v-yiruan-msft
Community Support
Community Support

Hi @admin11 ,

Please update the formula of measure [color by qtr] as below:

 

color by qtr = 
SWITCH (
    RIGHT ( SELECTEDVALUE ( 'Date'[yrqtr] ), 2 ),
    "1Q", "Green",
    "2Q", "Blue",
    "3Q", "Red",
    "4Q", "Grey"
)

 

yingyinr_0-1617073325121.png

Best Regards

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

View solution in original post

5 REPLIES 5
v-yiruan-msft
Community Support
Community Support

Hi @admin11 ,

Please update the formula of measure [color by qtr] as below:

 

color by qtr = 
SWITCH (
    RIGHT ( SELECTEDVALUE ( 'Date'[yrqtr] ), 2 ),
    "1Q", "Green",
    "2Q", "Blue",
    "3Q", "Red",
    "4Q", "Grey"
)

 

yingyinr_0-1617073325121.png

Best Regards

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

@v-yiruan-msft 

Thank you very much for your help , it work fine , apprecaite a lot.

Paul

@admin11 

Hi Paul,

Didn't my code work?  It produces the results you asked for?

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!


PhilipTreacy
Super User
Super User

@admin11 

Hi Paul,

 

Download PBIX

 

This code works

 

 

color by qtr = 

VAR __Qtr = SELECTEDVALUE('Date'[Year Quarter])

RETURN

SWITCH(
    
    TRUE(),
    

    CONTAINSSTRING(__Qtr, "Q1"), "green",

    CONTAINSSTRING(__Qtr, "Q2"), "blue",

    CONTAINSSTRING(__Qtr, "Q3"), "red",

    "gray"
)

 

 

colbars.png

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!


@PhilipTreacy 

I am sorry , i miss your reply. i just tested your is working fine.

also your code more easy to understand.

 

Paul

 

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.