Forum Discussion

DuncanYeah's avatar
DuncanYeah
Icon for Helper III rankHelper III
26 days ago
Solved

Color Theme change when dimension selection is changed.

Dear All,

I created a field parameter to allow dynamic switching of the dimension across different charts. However, when the dimension is changed, the color theme also changes, which is not the expected behavior.

Interestingly, this issue only happens with measures that use dynamic formatting.

Please help. Many Thx.

 

Best Regards,

Duncan

 

 

  • Hi DuncanYeah​,

    Thanks for sharing the additional details. You can try Field value conditional formatting to define chart colors based on the selected field parameter.

    Microsoft documents an approach that uses a color column in the field parameter table. To configure it, select the visual, open Format visual, go to the data color settings, select fx, choose Field value as the format style, and select the color column.

    One limitation is that this approach works when a single field parameter option is selected. It doesn't assign separate colors when multiple parameter options appear in the same chart.

    Since your measures require dynamic format strings, you can test this approach with your existing measure-selection logic to see whether it meets your color requirements while retaining your current formatting.

    For more details, please refer to the below Official Microsoft Documentation:

    Apply conditional formatting to chart lines and legends in Power BI - Power BI | Microsoft Learn

    Create dynamic format strings for measures - Power BI | Microsoft Learn

    I hope this helps. Please feel free to reach out if you have any further questions.
    Thank you.

     

6 Replies

  • Hi DuncanYeah​ -  we can control the palette in the theme, not in the visual. Select the visual and go to Format >> Columns >> Colors. Click Reset to default to clear any per-series overrides. Set your colors in a custom theme JSON, in the order you want them assigned:

    Json Script attached.

    Import it via View >> Themes >> Browse for themes.                                                                      Every dimension in the field parameter will now take color 1, 2, 3… in a predictable way, whatever the measure’s formatting.

    Hope this helps.

  • Hi @, 

    the legend colors are most likely being re-assigned by position from the theme palette whenever the legend field changes. Manual colors set in the format pane are tied to the specific values of one field, so after the parameter switches dimensions, those values no longer exist and Power BI falls back to the default palette order. I couldn’t find documentation explaining why it only happens with dynamic format string measures. It looks like a rendering quirk rather than a setting you’ve missed.

    Things to try:

    1. Isolate the trigger: Temporarily swap one affected measure’s dynamic format string for a normal static format. If the colors stay stable, dynamic formatting is the cause, and it’s worth reporting on the Power BI Issues forum with a small repro.
    2. Drive colors with a measure: Go to Format > Colors > fx > Format style: Field value, and use a measure that returns hex codes. Conditional formatting supports legend colors, and the measure must return text. Build the measure with SWITCH on the selected legend value, so each category keeps its color whichever dimension is active. microsoft
    3. Keep the dynamic format out of the visual: If you only need dynamic formatting for display, apply it on a separate measure used in a table or card, and keep the chart’s measure on a static format.

    If option 1 confirms it, option 2 is the most reliable permanent fix.

    Sources:
    https://learn.microsoft.com/lv-lv/Power-Bi/visuals/power-bi-visualization-conditional-formatting

  • Hi DreamITLearn​,rajendraongole1​ ,

    Thanks for the reply. 
    I implement the fileprm.json into my dashboard. The color still change but seem in the same color theme.



    And as DreamITLearn​ said, I tried to remove dynamic formatting from my measure. However, as requested I need to provide dimension and measure selection, and each measure have different request on unit display. It is not  possible to remove dynamic formatting. 

     

    After all thank both of your replies.

    Best Regards,

    Duncan

     

    • v-abhinavmu's avatar
      v-abhinavmu
      Icon for Community Support rankCommunity Support

      Hi DuncanYeah​,

      Thanks for sharing the additional details. You can try Field value conditional formatting to define chart colors based on the selected field parameter.

      Microsoft documents an approach that uses a color column in the field parameter table. To configure it, select the visual, open Format visual, go to the data color settings, select fx, choose Field value as the format style, and select the color column.

      One limitation is that this approach works when a single field parameter option is selected. It doesn't assign separate colors when multiple parameter options appear in the same chart.

      Since your measures require dynamic format strings, you can test this approach with your existing measure-selection logic to see whether it meets your color requirements while retaining your current formatting.

      For more details, please refer to the below Official Microsoft Documentation:

      Apply conditional formatting to chart lines and legends in Power BI - Power BI | Microsoft Learn

      Create dynamic format strings for measures - Power BI | Microsoft Learn

      I hope this helps. Please feel free to reach out if you have any further questions.
      Thank you.

       

      • v-abhinavmu's avatar
        v-abhinavmu
        Icon for Community Support rankCommunity Support

        Hi DuncanYeah​,

        I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. 

        Thank you.

  • v-abhinavmu's avatar
    v-abhinavmu
    Icon for Community Support rankCommunity Support

    Hi DuncanYeah​,

    May I check if this issue has been resolved? If not, Please feel free to contact us if you have any further questions.

    Thank you