Dynamic color change of bar chart with Filed Parameter

Md Mizanur Rahman Nayan 0 Reputation points
2025-01-18T12:32:54.09+00:00

Normally the below code works when i am not working with Filed Parameters. But when i am using it with field parameter, its returning error
MdxScript(Model) (431, 21) Calculation error in measure •_measurei[Max bar dept.org Resignation]: Column [Dept.Org Lvl] is part of composite key, but not all columns of the composite key are included in the expression or its dependent expression.

Overall Max/Min linechart Overall Attrition = 
VAR Resignation = [# of resignation]
VAR SelectedField = SELECTEDVALUE('Age-tenure'[Age-tenure])
VAR MaxResignation = 
    SWITCH(
        SelectedField,
        "Age Banding", MAXX(ALLSELECTED(fact_employee[Age Band]), [Overall Attrition Rate]),
        "Tenure Banding", MAXX(ALLSELECTED(fact_resigned[Tenure Banding]), [Overall Attrition Rate])
    )
VAR MinResignation = 
    SWITCH(
        SelectedField,
        "Age Banding", MINX(ALLSELECTED(fact_employee[Age Band]), [Overall Attrition Rate]),
        "Tenure Banding", MINX(ALLSELECTED(fact_resigned[Tenure Banding]), [Overall Attrition Rate])
    )
-- Determine the color based on Max and Min
VAR Result =
    SWITCH(
        TRUE(),
        Resignation = MaxResignation, "RED",
        Resignation = MinResignation, "Green",
        "#751d84"
    )
RETURN
Result
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
41,752 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Syed Saleem Peera 11,005 Reputation points Microsoft Vendor
    2025-01-20T03:55:41.06+00:00

    Hi Md Mizanur Rahman Nayan,

    Thank you for reaching out to us on the Microsoft Q&A forum. 

    This topic is currently not supported in the Q&A forums. 

    We recommend initiating a new discussion through the https://community.fabric.microsoft.com/t5/Power-BI-forums/ct-p/powerbi

    Moderators are readily available there to assist you and provide guidance. 

    Please don't forget to Accept/Upvote helpful answer and close this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.