Forum Discussion
Matrix conditionally format each column independently
Hi,
I have a matrix table containing 30 columns (CR 01 to CR 30) based on measures. I need apply conditionally format (background gradient color) to each column independently. And in the same time this contidional format must work separately within the hierarchy (separately for years, separately for months and separately for days)
Is there any way to apply conditional format to columns not to rows?
Thank you in advance for any advice
2 Replies
- FarhanJeelaniSuper User
Dear elgato ,
Please follow the below steps:
Create Measures for Each Column: For each column (e.g., CR 01, CR 02), create a DAX measure to calculate the dynamic color. For instance:
CR01_Color = VAR MinValue = CALCULATE(MIN([CR 01]), ALLSELECTED('Table')) VAR MaxValue = CALCULATE(MAX([CR 01]), ALLSELECTED('Table')) VAR CurrentValue = [CR 01] RETURN SWITCH( TRUE(), CurrentValue <= MinValue, "#FF0000", CurrentValue >= MaxValue, "#00FF00", "#FFFF00" )Repeat this for all other columns (e.g., CR02_Color, CR03_Color).
Apply Conditional Formatting:
- Open the Format Visual pane.
- Locate the Conditional Formatting settings for the matrix.
- Add Background Color formatting for each measure (CR 01, CR 02, etc.).
- Choose the field value option and reference the appropriate color measure (e.g., CR01_Color).
Ensure Hierarchical Independence: Modify the DAX measures to account for the context of hierarchy levels, such as Year, Month, or Day. For example:
CR01_Year_Color = VAR MinValue = CALCULATE(MIN([CR 01]), ALLEXCEPT('DateTable', 'DateTable'[Year])) VAR MaxValue = CALCULATE(MAX([CR 01]), ALLEXCEPT('DateTable', 'DateTable'[Year])) VAR CurrentValue = [CR 01] RETURN SWITCH( TRUE(), CurrentValue <= MinValue, "#FF0000", CurrentValue >= MaxValue, "#00FF00", "#FFFF00" )Replace the context of the calculation to work at the desired level of the hierarchy (Year, Month, or Day).
Dynamic Solution for Large Columns: Instead of creating multiple measures, use a dynamic measure approach:
Dynamic_Color = VAR Column = SELECTEDVALUE('Columns'[ColumnName]) VAR MinValue = CALCULATE(MIN([ColumnValue]), ALLSELECTED('Table')) VAR MaxValue = CALCULATE(MAX([ColumnValue]), ALLSELECTED('Table')) VAR CurrentValue = [ColumnValue] RETURN SWITCH( TRUE(), CurrentValue <= MinValue, "#FF0000", CurrentValue >= MaxValue, "#00FF00", "#FFFF00" )Validation: Test the formatting across hierarchy levels to ensure it applies independently at each level (Year, Month, Day).
Performance Optimization: For larger datasets, simplify DAX expressions to avoid overloading the model.
Please mark this as solution if it helps you. Appreciate Kudos.
- elgatoNew Member
thank you fo reply!
But this solution doesn`t work properly for me
thank you anyway!