Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
smpa01
Community Champion
Community Champion

CG Conditional formatting issue wth string

@AlexisOlson @parry2k @BernatAgulloMVP 

 

I am using calculation group to scale up my current project. CG is working beautifully except

the conditional formatting with calculation group fails when the measure returns a string but works if if it is a double.

 

Works when DOUBLE

smpa01_0-1740500476266.png

 

 

 

Fails when STRING, the measure does not even evaluate correctly

smpa01_2-1740500712942.png

 

 

What am I doing wrong, how this can be fixed?

 

I want to be able to use existing calculation group and be able to conditionally format based on STRING.

 

PFA minimally produced sample of a large data model highlighting only the issue.

 

Thank you in advance.

 


========================
Did I answer your question? Mark my post as a solution!
Proud to be a Super User
My Custom Visualization Projects
• Plotting Live Sound: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
• Week 3: View
• Week 4: View
========================
3 REPLIES 3
Anonymous
Not applicable

Hi @smpa01 ,

Based on the information, try using the following DAX formula.

VAR xx =CALCULATE ( [left_selected], CG[Name] = "diff" ) 

-- output type String -- possible values {'y','n'}
VAR yy = CALCULATE ( [left_selected], CG[Name] = "is_negative" )
VAR yy_numeric = IF ( yy = "n", "n", "y" )

VAR conds =
    SWITCH (
        TRUE (),
        ------------------Works----------------------------
        //currentField = "is_negative" && xx>0,1
        //,currentField = "is_negative" && xx<0,-1
        -----------------DOES NOT WORK ---------------------
        currentField = "is_negative" && yy_numeric = "n", "n",
        currentField = "is_negative" && yy_numeric = "y", "y" 
        //  currentField = "is_negative" && yy_numeric = 1, "n",
        //  currentField = "is_negative" && yy_numeric = -1, "y" 
        ------------------Works-------------------------------
        //currentField = "is_negative" && xx > 0, "n",
        //currentField = "is_negative" && xx < 0, "y"

        ,BLANK()
    )
//VAR debugger = SWITCH ( TRUE (), currentField = "is_negative", xx )
RETURN
    conds

vjiewumsft_0-1740558237469.png

Best Regards,

Wisdom Wu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

smpa01
Community Champion
Community Champion

@Anonymous  thank you very much and it worked in the sample provided.

 

However, can you please explain why it works? Without fully understanding the WHY this can't be utilized in Production. My measures are far more complex than the described in sample.

 

Therefore, can you please possibly provide me with an explanation of this behavior so that in any similar circumstances, currently known (as the issue described in the question) or unknown I can navigate by myself.

 

Also, a deeper look into this calculation group shows it is a classic example of sideways recursion (unknowningly landed at it) which is not advised. I am willing to alter the entire calculation item authoring from this way to prevent further slipping into black hole in Production.

 

Can you please shed some light? I am willing to hear your thoughts.

 


========================
Did I answer your question? Mark my post as a solution!
Proud to be a Super User
My Custom Visualization Projects
• Plotting Live Sound: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
• Week 3: View
• Week 4: View
========================
Anonymous
Not applicable

Hi ,

I think the [left_selected] measure calculates numeric values and cannot be compared directly to strings. So direct comparison has no effect. Using If function to determine the size of the value.

vjiewumsft_0-1740646984115.png

 

Best Regards,

Wisdom Wu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.