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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Color format by category in stacked chart with condition.

Hello,

I want to make a mesure that make a colorisation when a value is more than another value select on a slicer filter. This measure will be integrate on a stacked diagram. I've already try to write a DAX code for this problematic but it doesn't work : 
---------------------------------------------------
Pareto art val CF =
VAR ParetoValue = [_Pareto article val %]
VAR SeuilPareto = [Valeur Seuil pareto]

 

VAR Categorie =
        ADDCOLUMNS('Data',
        "Statut ancienneté dyna",
        if([_Pareto article val %] <= [Valeur Seuil pareto],'Data'[Statut ancienneté],"Autre"
        ))
   
RETURN
IF(
    [_Pareto article val %] <= [Valeur Seuil pareto] ,
    SWITCH(
        ,
        Categorie = "Catégorie 1 :  <= 1 mois", "#118DFF",
        Categorie = "Catégorie 2 :  <= 3 mois", "#EFD807",
        Categorie = "Catégorie 3 :  <= 6 mois", "#F6A02F",
        Categorie = "Catégorie 4 :  > 6 mois", "#FA0400",
        Categorie = "Autre", "#a9a9a9"
    )
)
------------------------
The two measure initialize at the start of the DAX code return just a value.
Someone can help me please. 
2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , hope you are using true in switch

you can have a measure like

 

IF(
[_Pareto article val %] <= [Valeur Seuil pareto] ,
SWITCH( true() ,
Max('Data'[Statut ancienneté]) = "Catégorie 1 : <= 1 mois", "#118DFF",
Max('Data'[Statut ancienneté]) = "Catégorie 2 : <= 3 mois", "#EFD807",
Max('Data'[Statut ancienneté]) = "Catégorie 3 : <= 6 mois", "#F6A02F",
Max('Data'[Statut ancienneté]) = "Catégorie 4 : > 6 mois", "#FA0400",
 "#a9a9a9"
)
)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thanks for your response but this is not the expect result :

Irache_0-1677853011213.png

In this case I don't know if they have a several category for one value like for this graph:

Irache_1-1677853232938.png

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors