Forum Discussion

ArchStanton's avatar
ArchStanton
Power Participant
1 year ago
Solved

Conditional Formatting

Hi,

Each month I am manually changing the font colour of the values below from red to black (red being future months).
I would like to do this automatically when we start a new month - how can I do this?

 

My data calendar has a MonthSort columns as well as a month number, the month sort consists of 202401, 202402 and so on and my month sort is just 1 to 12.

The measures i am currently using for the 3 columns are:

 

Original Forecast = 
    VAR _firstdate = 
            CALCULATE(MIN('Total Closures'[Month]),
            FILTER('Modelling','Modelling'[Forecast] <> BLANK() )
            )
    RETURN
        CALCULATE(
                MIN('Modelling'[Forecast]),
                FILTER ('Modelling', Modelling[Month] = _firstdate)
        )

 

 

Actual incl Projected = SUM(Modelling[Actual & Projected])

 

 

% Difference2 = 
([Actual incl Projected]-[Original Forecast]) / [Last Value Forecast]

 

 

I'd be grateful for any advice

  • Hi, please follow these steps:
    For table1 to see only future months, please create the following measure:

    IsFutureMonth = 
    IF(
        LASTDATE('Date'[Date]) > EOMONTH(TODAY(),0),
        1,
        0
    )

     

    For table2, to see only future and present month, please create the following measure:

    IsFutureMonthPresent = 
    IF(
        LASTDATE('Date'[Date]) >= EOMONTH(TODAY(),0),
        1,
        0
    )

     

    Now lets format your visual.

    Select your table1, and in the Values field, right click on desired measure and add a conditional formatting as shown bellow:

     

    In the prompt, in format style, choose Rules based on isFutureMonth measure, and color red when the value is 1, make sure to choose number and not percent, as shown bellow:

    Repeat this steps for other values that you want to format in your matrix, and for you table2, just format using the measure isFuturePresent.

     

    Your final result should look like this:

     

    Download the sample: Case Modelling - Copy 

     

     

     

     

9 Replies

  • Hi ArchStanton 
    Assuming your MonthSort column contains values like 202401, 202402, etc., and your Month Number column contains values from 1 to 12, you can create a DAX measure as follows:

     

    IsFutureMonth = 
    VAR CurrentMonth = YEAR(TODAY()) * 100 + MONTH(TODAY())
    RETURN
    IF(MAX('Calendar'[MonthSort]) > CurrentMonth, 1, 0)

     

     

    • Go to the table visual where you want to apply the formatting.
    • Select the column you want to format.
    • Click on the dropdown arrow next to the column name and choose “Conditional formatting” > “Font color.”
    • In the conditional formatting pane, choose “Field value” and select the measure IsFutureMonth.
    • Set the color for 1 (future months) to red and 0 (current and past months) to black.

     

     

    • ArchStanton's avatar
      ArchStanton
      Power Participant

      Thanks, unfortunately It won't accept anything in Field value:

       

      • Bibiano_Geraldo's avatar
        Bibiano_Geraldo
        Super User

        Hi, please follow these steps:
        For table1 to see only future months, please create the following measure:

        IsFutureMonth = 
        IF(
            LASTDATE('Date'[Date]) > EOMONTH(TODAY(),0),
            1,
            0
        )

         

        For table2, to see only future and present month, please create the following measure:

        IsFutureMonthPresent = 
        IF(
            LASTDATE('Date'[Date]) >= EOMONTH(TODAY(),0),
            1,
            0
        )

         

        Now lets format your visual.

        Select your table1, and in the Values field, right click on desired measure and add a conditional formatting as shown bellow:

         

        In the prompt, in format style, choose Rules based on isFutureMonth measure, and color red when the value is 1, make sure to choose number and not percent, as shown bellow:

        Repeat this steps for other values that you want to format in your matrix, and for you table2, just format using the measure isFuturePresent.

         

        Your final result should look like this:

         

        Download the sample: Case Modelling - Copy 

         

         

         

         

    • ArchStanton's avatar
      ArchStanton
      Power Participant

      I tried this and there is no formatting at all in the Original Forecast column:

       

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thanks for the reply from Bibiano_Geraldo , please allow me to provide another insight:

    Hi, ArchStanton 

    1.Firstly, I have created the following sample data based on your description:

    2.Secondly, I have created the following measure to determine whether the current date meets the requirements:

    MEASURE =
    IF (
        MONTH ( MAX ( 'Total Closures'[ Month] ) ) >= MONTH ( TODAY () )
            || YEAR ( MAX ( 'Total Closures'[ Month] ) ) > YEAR ( TODAY () ),
        "red",
        "black"
    )
    

    3.Next, modify the colours column by column in the position shown in the image below:

    Note that every column in the visualization that you need to change color needs to be modified.

    4.Here's my final result, which I hope meets your requirements.

    Please find the attached pbix relevant to the case.

     

    Best Regards,

    Leroy Lu

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

    • ArchStanton's avatar
      ArchStanton
      Power Participant

      Hi, thanks for your reply.

      Unfortunately its still not working.

       

      My data model is a simple one:

      The Month column in my date table is Text = 

       

      Month = FORMAT('Date'[Date], "MMM")

       

       

      and so I get this error message with your measure:

      When I modify your measure to this then the formatting stays all black for the Original Forecast column:

       

      Red or Black = 
      IF (
          MONTH ( MAX ( 'Date'[Date] ) ) >= MONTH ( TODAY () )
              || YEAR ( MAX ( 'Date'[Date] ) ) > YEAR ( TODAY () ),
          "red",
          "black"
      )

       

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi, ArchStanton 

        Thank you for your response.

         

        As you suspected, we believe this issue might be caused by table relationships. We would appreciate it if you could provide your PBIX file so that we can tailor the solution based on your specific details.

         

        We recommend uploading it to GitHub and sharing the link with us.When uploading a file, please be careful to delete sensitive information.

         

        Looking forward to your reply.

         

        Best Regards,

        Leroy Lu