The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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:
Which Chart I am using and the data underneath :
A sample of the data:
Financial Year Month Proper | start_date | segment2 | segment | Base |
FY2024 July | 01/07/2023 0:00 | No Purchase | New Customers | 15432 |
FY2024 July | 01/07/2023 0:00 | No Purchase | Prospects | 345678 |
FY2024 July | 01/07/2023 0:00 | Active | First Timers | 52341 |
FY2024 July | 01/07/2023 0:00 | Active | Repeat | 23456 |
FY2024 July | 01/07/2023 0:00 | Active | Loyal | 45678 |
FY2024 July | 01/07/2023 0:00 | Active | VIP | 2789 |
FY2024 July | 01/07/2023 0:00 | Active | At Risk | 16543 |
FY2024 July | 01/07/2023 0:00 | Inactive | Inactive | 92345 |
FY2024 July | 01/07/2023 0:00 | Inactive | Lapsed | 328976 |
FY2024 August | 01/08/2023 0:00 | No Purchase | New Customers | 12567 |
FY2024 August | 01/08/2023 0:00 | No Purchase | Prospects | 359876 |
FY2024 August | 01/08/2023 0:00 | Active | First Timers | 48765 |
FY2024 August | 01/08/2023 0:00 | Active | Repeat | 24567 |
FY2024 August | 01/08/2023 0:00 | Active | Loyal | 54321 |
FY2024 August | 01/08/2023 0:00 | Active | VIP | 2654 |
FY2024 August | 01/08/2023 0:00 | Active | At Risk | 17654 |
FY2024 August | 01/08/2023 0:00 | Inactive | Inactive | 95432 |
FY2024 August | 01/08/2023 0:00 | Inactive | Lapsed | 337654 |
Does anyone has an idea on how to fix this ? or if it is even possible to do so ?
Thanks !
Solved! Go to Solution.
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
)
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
)