Forum Discussion

Milozebre's avatar
Milozebre
Helper V
6 years ago
Solved

Colors based on parameters

Hello Community, 

 

I hope you are doing well, you and your families. I have a question, I found the beginnings of answers on this forum but I can't seem to do what I would like. Here is the background: I have two parameters: "Year analyzed" and "Comparison Year". As you can see from the diagram, the year of comparison is always the same and the other changes a color for the week, another for Saturday and the other Sunday.

 

Thank you for your help 

  • Hello 

    I dont find solution with a measure. 

    Anytime I put a legend to see year, its not working anymore.

     

    With the measure and if I put the paramter table as legend and not the Year, its working. 

     

    Thank you for your help, youre awesome

10 Replies

  • Mariusz's avatar
    Mariusz
    Community Champion

    Hi Milozebre 

     

    You can add a  day of the week number column to your date dimension, later use it for conditional formating of you chart as below

     

    Best Regards,
    Mariusz

    If this post helps, then please consider Accepting it as the solution.

    Please feel free to connect with me.
    LinkedIn

     

    • Milozebre's avatar
      Milozebre
      Helper V

      Hello Mariusz 

       

      thank you for the reply. 

      As you can see on the chart above, what is gray is the year of analysis ex 2018
      and in blue, the year of comparison. Gray can't change.
      The analysis year which is a parameter must always be gray and the year of comparison on the basis of days must have the predefined colors.
      I wanted to make measurements with Swhith but I don't know how to incorporate the parameters:
      Year analyze = "Gray"
      If day = "Job" with Year comparison; "Red"
      for example

       

  • Check color by rule and color by value

    https://docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting

     

    Few examples of measure that can used in color by values after selecting fields

    Color Date = if(FIRSTNONBLANK('Date'[date],TODAY()) <today(),"lightgreen","red")
    
    Color sales = if(AVERAGE(Sales[Sales Amount])<170,"green","red")
    Color Year = if(FIRSTNONBLANK('Date'[Year],2014) <=2016,"lightgreen",if(FIRSTNONBLANK('Date'[Year],2014)>2018,"red","yellow"))
    
    • Milozebre's avatar
      Milozebre
      Helper V

      Hello amitchandak 

       

      Thank you for the reply

       

      I create a measure like this : 

      Mesure Jourcouleur =
      SWITCH(
      SELECTEDVALUE(Comptage[jour]);
      "JOB";"#009AA6";
      "Samedi";"#A1006B";
      "Dimanche";"#659200")
      Its working 
      But When i choose 2 years, But when I choose 2 years, it works for both. Now I would like that for the previous year, the color be gray and for the current year, the colors that are in the measure
       
      Thank you 

       

       

       

      • amitchandak's avatar
        amitchandak
        Super User

        Combine with max year and create one or more combinations

        If(max(Table[year]) =2007,
        SWITCH(
        SELECTEDVALUE(Comptage[jour]);
        "JOB";"#009AA6";
        "Samedi";"#A1006B";
        "Dimanche";"#659200"),
        ///change the color for another year
        SWITCH(
        SELECTEDVALUE(Comptage[jour]);
        "JOB";"#009AA6";
        "Samedi";"#A1006B";
        "Dimanche";"#659200") )
  • Hello, 

     

    I try this measure : 

    Mesure Jourcouleur2017 =
    SWITCH(
    TRUE();
    SELECTEDVALUE(Calendrier[Year]) = 2017;"#B3B3B3";
    SELECTEDVALUE(Calendrier[Year]) = 2018; "#E3E3E3")
     
    Its working, if i choose only year. 
    But I need to add a legend (jour)
    When i put in legend (see image), i loose my conditionnal formating. 
    Is it possible to say in the measure below. 
    For year 2017 and for all "jour" for 2017 the color is Gray and for the others years 3 others colors ? 
  • Icey's avatar
    Icey
    Community Support

    Hi Milozebre ,

     



     


    Is this what you want?

    If the visual is Clustered column chart, you can't set conditional formating on it. Conditional formatting applies only to the values of Table or Matrix visuals.

    So, I'm afraid what you want is not possible currently.

     

     

    Best Regards,

    Icey

     

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

    • Milozebre's avatar
      Milozebre
      Helper V

      Hello Icey , 

       

      I can put some contionnal formating on clustered column chart as you see with this measure (see image) : 

      Mesure Jourcouleur JOB =
      SWITCH(
      TRUE();
      SELECTEDVALUE(Calendrier[Year]) = 2017;"#B3B3B3";
      SELECTEDVALUE(Calendrier[Year]) <>2017;"#A1006B")
       
      But when I put year in legend or if i choose 2 year, its not working, i loose the formatting, thats my problem. 
      I want to see a color for 2017 and 2018 via the measurement.
      Because I would have to have a 2018 and 2019 file.
      And in this case, 2018 should be gray and 2019 the other color.
      Basically
      year min = always gray
      max year = custom color.
      It works until I put a field in legend
       
      Thank you 
      • Milozebre's avatar
        Milozebre
        Helper V

        Hello 

        I dont find solution with a measure. 

        Anytime I put a legend to see year, its not working anymore.

         

        With the measure and if I put the paramter table as legend and not the Year, its working. 

         

        Thank you for your help, youre awesome