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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
SSteven
New Member

How to Maintain Consistent Segment Colors Across a Hierarchy Visual

Hi, 

 

I've been struggling with maintaining consistent colors for segments in my Power BI hierarchical visualizations, particularly when dealing with different months of data. Here's my specific issue and how I am trying to resolve it. 

 

Problem: I have a column and line chart showing customer segments in a hierarchy (No Purchase/Active/Inactive as parent level, with sub-segments like New Customers, Prospects, etc.). When filtering by different months, the colors of my segments keep changing. I need these segments to maintain the same colors consistently.

 

Attempted Solutions That Didn't Work: I tried creating a DAX measure for colors but this isn't working and is just retuning the default value. 

 

 

 

Segment_Color = 
SWITCH(
    TRUE(),
    // No Purchase Categories
    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = "New Customers, No Purchase", "#D2B48C",  // Tan color
    
    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = "Prospects, No Purchase", "#B5C2CD",  // Dark Grey color

    // Active Categories
    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = "First Timers, Active", "#D4C4C8",  // Mauve/pink

    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = "Repeat, Active", "#B8BDB5",  // Lavender

    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = "Loyal, Active", "#B8C7B5",  // Sage green

    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = "VIP, Active", "#D2B48C",  // Tan color

    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = "At Risk, Active", "#6A5D8D",  // Purple

    // Inactive Categories
    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = "Inactive, Inactive", "#D9D9D9",  // Light grey

    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = "Lapsed, Inactive", "#E6E6E6",  // Lighter grey

    "#CCCCCC" // Default color if none of the above conditions are met
)

 

 

 

 
Use of the measure as a column conditionnal formatting: 

SSteven_0-1732671626239.png


Which Chart I am using and the data underneath : 

SSteven_1-1732671676239.png

 

A sample of the data: 

Financial Year Month Properstart_datesegment2segmentBase
FY2024 July01/07/2023 0:00No PurchaseNew Customers15432
FY2024 July01/07/2023 0:00No PurchaseProspects345678
FY2024 July01/07/2023 0:00ActiveFirst Timers52341
FY2024 July01/07/2023 0:00ActiveRepeat23456
FY2024 July01/07/2023 0:00ActiveLoyal45678
FY2024 July01/07/2023 0:00ActiveVIP2789
FY2024 July01/07/2023 0:00ActiveAt Risk16543
FY2024 July01/07/2023 0:00InactiveInactive92345
FY2024 July01/07/2023 0:00InactiveLapsed328976
FY2024 August01/08/2023 0:00No PurchaseNew Customers12567
FY2024 August01/08/2023 0:00No PurchaseProspects359876
FY2024 August01/08/2023 0:00ActiveFirst Timers48765
FY2024 August01/08/2023 0:00ActiveRepeat24567
FY2024 August01/08/2023 0:00ActiveLoyal54321
FY2024 August01/08/2023 0:00ActiveVIP2654
FY2024 August01/08/2023 0:00ActiveAt Risk17654
FY2024 August01/08/2023 0:00InactiveInactive95432
FY2024 August01/08/2023 0:00InactiveLapsed337654


Does anyone has an idea on how to fix this ? or if it is even possible to do so ? 

Thanks ! 

1 ACCEPTED SOLUTION
SSteven
New Member

Resolved it. 
Was in a tunnel vision, just had to eat. 

This is the measure solution to use in the Conditionnal Formatting (in the Column section):  

Segment_Color = 
SWITCH(
    TRUE(),
    // No Purchase Categories
    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & "No Purchase, New Customers", "#D2B48C",  // Tan color
    
    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & "No Purchase, Prospects", "#B5C2CD",  // Dark Grey color

    // Active Categories
    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & "Active, First Timers", "#D4C4C8",  // Mauve/pink

    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & "Active, Repeat", "#B8BDB5",  // Lavender

    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & "Active, Loyal", "#B8C7B5",  // Sage green

    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & "Active, VIP", "#D2B48C",  // Tan color

    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & "Active, At Risk", "#6A5D8D",  // Purple

    // Inactive Categories
    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & "Inactive, Inactive", "#D9D9D9",  // Light grey

    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & "Inactive, Lapsed", "#E6E6E6",  // Lighter grey

    "#CCCCCC" // Default color if none of the above conditions are met
)

 

 

View solution in original post

1 REPLY 1
SSteven
New Member

Resolved it. 
Was in a tunnel vision, just had to eat. 

This is the measure solution to use in the Conditionnal Formatting (in the Column section):  

Segment_Color = 
SWITCH(
    TRUE(),
    // No Purchase Categories
    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & "No Purchase, New Customers", "#D2B48C",  // Tan color
    
    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & "No Purchase, Prospects", "#B5C2CD",  // Dark Grey color

    // Active Categories
    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & "Active, First Timers", "#D4C4C8",  // Mauve/pink

    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & "Active, Repeat", "#B8BDB5",  // Lavender

    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & "Active, Loyal", "#B8C7B5",  // Sage green

    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & "Active, VIP", "#D2B48C",  // Tan color

    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & "Active, At Risk", "#6A5D8D",  // Purple

    // Inactive Categories
    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & "Inactive, Inactive", "#D9D9D9",  // Light grey

    SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & 
    SELECTEDVALUE('dataset'[segment2]) & ", " & 
    SELECTEDVALUE('dataset'[Segment]) = SELECTEDVALUE('DimDate'[Financial Year Month Proper]) & ", " & "Inactive, Lapsed", "#E6E6E6",  // Lighter grey

    "#CCCCCC" // Default color if none of the above conditions are met
)

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors