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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Irache
Helper II
Helper II

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

@Irache , 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

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.