Forum Discussion

RAYAN123's avatar
RAYAN123
New Member
1 month ago

Conditional formatting for matrix column headers based on closed month

Hi all,

I am working with a Power BI matrix where I have months (January–December) displayed as column headers, as shown in the screenshot. no value will display, only the column

Kindly ask for below request solution

  • Dynamically change the background color of the column headers
  • If a month is financially closed → show green
  • If a month is still open → show grey

I have a DAX in my model (e.g., a measure or flag indicating whether a month is closed):

Closed Month Flag =
IF(
    SELECTEDVALUE('Time'[IsClosedMonth]) = TRUE(),
    1,
    0
)

so the challenge is only related to applying the formatting to the headers.

Thanks for support!

2 Replies

  • Rupa01's avatar
    Rupa01
    Solution Sage

    Hi RAYAN123

    Currently, Power BI does not support conditional formatting for matrix column headers. Conditional formatting can only be applied to values within the visual, not to row or column headers.

    If your requirement is to dynamically color the month header itself, you can use the Deneb custom visual.
     
    I have provided below Deneb custom visual example using Sample Data - Time Sample

    1. Create a custom column MonthHeaderColor

    MonthHeaderColor = 
    IF(
        'Time Sample'[IsClosedMonth] = TRUE(),
        "#70AD47",   -- Green
        "#A6A6A6"    -- Grey
    )

    2. Add Month, MonthNo, IsClosedMonth and MonthHeaderColor to the Values in Deneb Visual.

    3. Edit Visual and select Vega-Lite (empty).

    4. Add below to the Specification section and Run.

    {
      "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
      "data": { "name": "dataset" },
    
      "transform": [
        {
          "calculate": "'Header'",
          "as": "HeaderRow"
        }
      ],
    
      "width": { "step": 70 },
      "height": 45,
    
      "layer": [
        {
          "mark": {
            "type": "rect",
            "stroke": "white",
            "strokeWidth": 1,
            "cornerRadius": 2
          },
          "encoding": {
            "x": {
              "field": "Month",
              "type": "ordinal",
              "sort": { "field": "MonthNo", "order": "ascending" },
              "axis": null
            },
            "y": {
              "field": "HeaderRow",
              "type": "nominal",
              "axis": null
            },
            "color": {
              "field": "MonthHeaderColor",
              "type": "nominal",
              "scale": null,
              "legend": null
            },
            "tooltip": [
              { "field": "Month", "type": "nominal", "title": "Month" },
              { "field": "IsClosedMonth", "type": "nominal", "title": "Closed?" }
            ]
          }
        },
        {
          "mark": {
            "type": "text",
            "align": "center",
            "baseline": "middle",
            "fontSize": 13,
            "fontWeight": "bold",
            "color": "white"
          },
          "encoding": {
            "x": {
              "field": "Month",
              "type": "ordinal",
              "sort": { "field": "MonthNo", "order": "ascending" }
            },
            "y": {
              "field": "HeaderRow",
              "type": "nominal"
            },
            "text": {
              "field": "Month",
              "type": "nominal"
            }
          }
        }
      ],
    
      "config": {
        "view": {
          "stroke": null
        }
      }
    }

    5. Result 

     

    💡 Helpful? Give a Kudos 👍 — keep the community growing
     Solved your issue? Mark as Solution ✔️ — help others find it faster

    Best regards,
    Rupasree Achari | BI & Fabric Analytics Engineer
    • Rupa01's avatar
      Rupa01
      Solution Sage

      RAYAN123did you get a chance to review the solution provided?

      If it helped resolve your issue, please consider marking it as Accepted Solution so it can benefit others in the community as well.

      Let me know if you need any further assistance! 👍