Forum Discussion

SS_1122's avatar
SS_1122
Frequent Visitor
3 years ago
Solved

Colour text according to condition

Hi All,

I am having a bit of trouble to get this right. I have a data set with dates and 2 columns Submitted and Delivered, if values for both the columns are 1, then file has been "successfully transfered" and if either is not 1 , then it gives something like "Not successful". To achieve this I created a new column in the data to check if both values are 1 or not. Now, I am creating a card based on the new column value which says "successfully transfered" or "not successful" and now based on the above condition I am trying to put a rule to colour it green when successful and red when not.



So the final result is I am looking for a card where if the file is successful to get the text in green and if not then the text should be in red.

Thanks.

  • Hi, SS_1122 

    Thank you for your quick response, based on your description you want to show the green and red color according to the return in your card visual. Right?

    Here are the steps you can refer to:

    (1)This is my test data:

     

     

    (2)We can create a measure to return the [Successful] of the last date. And we can put the measure on the card visual.

    Last Successful = var _date = MAX('Table'[Date])
    
    var _t = FILTER('Table','Table'[Date] =_date)
    
    return
    
    MAXX(_t,[Successful])

     

    (3)We need to create a measure to configure the text color in the card visual.

    Color Flag = IF([Last Successful] = "File Submission is successful","green","red")

     

    (4)Then we can configure it in the card visual:

     

     

    Then we can meet your need , the result is as follows:

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

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

     

4 Replies

  • Hi , SS_1122 

    According to your description, you want to " based on the above condition I am trying to put a rule to colour it green when successful and red when not.". Right?

    Here are the steps you can refer to :
    (1)This is my test data :

    (2)If your want to chow color in your table , you can click "New Measure" to crrate a measure:

    Measure = var _date = MAX('Table'[Date])
    var _sum =SUMX( FILTER('Table','Table'[Date] = _date) , [Delivered]+[Submitted])
    return
    IF(_sum=2,"green", "red")

    (3)Then you can configure it to the field you want:

     

    if you want to show the whole row color , you can configure it to the all fields in your visual:

    If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

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

     

    • SS_1122's avatar
      SS_1122
      Frequent Visitor

      Hey,

      Thank you for your help, I will try and explain the context better. 
      So, I have a given data with 3 columns - Date, Submitted and Delivered

      DateSubmitted Delivered
      10/10/202211
      11/10/202211
      12/10/202211
      13/10/202211
      14/10/202211
      15/10/202210
      16/10/202210
      17/10/202200
      18/10/202200
      19/10/202201
      20/10/202201
      21/10/202201
      22/10/202211
      23/10/202210
      24/10/202210
      25/10/202211
      26/10/202211
      27/10/202211
      28/10/202211
      29/10/202211
      30/10/202211
      31/10/202211
      01/11/202210
      02/11/202210
      03/11/202211
      04/11/202201
      05/11/202211
      06/11/202201
      07/11/202201
      08/11/202211
      09/11/202211

       

      Now, I create an additional column by transforming the data in power BI - to add another column whoch measure whether the files have been successfully delivered or not - to check this I write the rule as:
      Successful = if(sheet1[Submitted] = 1 && sheet1[Delivered] = 1 , "File Submission is successful" , if (sheet1[Submitted] = 0 && sheet1[Delivered] = 1, "File Submission is not successful" and so on. So, now my data looks something like this

      DateSubmitted DeliveredSuccessful 
      10/10/202211File Submission is successful 
      11/10/202211File Submission is successful 
      12/10/202211File Submission is successful 
      13/10/202211File Submission is successful 
      14/10/202211File Submission is successful 
      15/10/202210File Submission is not successful 
      16/10/202210File Submission is not successful 
      17/10/202200File Submission is not successful 
      18/10/202200File Submission is not successful 
      19/10/202201File Submission is not successful 
      20/10/202201File Submission is not successful 
      21/10/202201File Submission is not successful 
      22/10/202211File Submission is successful 
      23/10/202210File Submission is not successful 
      24/10/202210File Submission is not successful 
      25/10/202211File Submission is successful 
      26/10/202211File Submission is successful 
      27/10/202211File Submission is successful 
      28/10/202211File Submission is successful 
      29/10/202211File Submission is successful 
      30/10/202211File Submission is successful 
      31/10/202211File Submission is successful 
      01/11/202210File Submission is not successful 
      02/11/202210File Submission is not successful 
      03/11/202211File Submission is successful 
      04/11/202201File Submission is not successful 
      05/11/202211File Submission is successful 
      06/11/202201File Submission is not successful 
      07/11/202201File Submission is not successful 
      08/11/202211File Submission is  successful 
      09/11/202211File Submission is  successful 

       

      Now I have to create a card based on the last entry, if the last entry says the File Submission is successful =, then it will show something like this.

      My only query is how do I colour code the text with green when it says successful and red when not successful. 

      • v-yueyunzh-msft's avatar
        v-yueyunzh-msft
        Icon for Community Support rankCommunity Support

        Hi, SS_1122 

        Thank you for your quick response, based on your description you want to show the green and red color according to the return in your card visual. Right?

        Here are the steps you can refer to:

        (1)This is my test data:

         

         

        (2)We can create a measure to return the [Successful] of the last date. And we can put the measure on the card visual.

        Last Successful = var _date = MAX('Table'[Date])
        
        var _t = FILTER('Table','Table'[Date] =_date)
        
        return
        
        MAXX(_t,[Successful])

         

        (3)We need to create a measure to configure the text color in the card visual.

        Color Flag = IF([Last Successful] = "File Submission is successful","green","red")

         

        (4)Then we can configure it in the card visual:

         

         

        Then we can meet your need , the result is as follows:

         

        Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

         

        Best Regards,

        Aniya Zhang

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