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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
madison13g
Regular Visitor

Use Gradient AND Rules in Conditional Formatting

I am trying colour the background of my table using a gradient but based on one condition before assigning the maximum value of the gradient.

 

Is there any way to use both rules and gradient in the same background colour formatting?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi,@madison13g I am glad to help you.
According to your description, you want to change the Description of the records within the last one year to another color in order to highlight them?
Currently, Power BI allows either gradient-based formatting or rule-based formatting to be applied to the background color of table cells, but not both in the same field. Gradient-based formatting automatically applies a color scale based on the minimum and maximum values of the data or custom values that you define. On the other hand, rule-based formatting allows you to set specific colors based on predefined conditions or rules.
However, you can simulate the effect of a gradient background by creating a measure that returns a variety of results and displays approximate background colors based on the results.
If you think this is possible, you can take a look at my solution.
Here is the test data I created.

vjtianmsft_0-1714445049622.png

I have created a table of dates and now I am calculating the number of days between the dates in the table and the current time by creating a measure.
Multiple results are created in this measure.

vjtianmsft_1-1714445073958.png

Here is the DAX code.

MEASURE =
VAR tableDate =
    MIN ( 'YourTable'[t_Date] )
VAR nowData =
    TODAY ()
VAR differ =
    DATEDIFF ( nowData, tableDate, DAY )
RETURN
    SWITCH (
        TRUE (),
        -30 <= differ
            && differ <= 30, "red",
        30 < differ
            && differ <= 60, "red-orange",
        60 < differ
            && differ <= 183, "orange",
        183 < differ
            && differ <= 365, "yellow",
        differ > 365, "green",
        ""
    )

vjtianmsft_2-1714445142017.png

Manually simulate a color gradient by setting several colors of the gradient from the multiple results returned by measure.

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

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

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi,@madison13g I am glad to help you.
According to your description, you want to change the Description of the records within the last one year to another color in order to highlight them?
Currently, Power BI allows either gradient-based formatting or rule-based formatting to be applied to the background color of table cells, but not both in the same field. Gradient-based formatting automatically applies a color scale based on the minimum and maximum values of the data or custom values that you define. On the other hand, rule-based formatting allows you to set specific colors based on predefined conditions or rules.
However, you can simulate the effect of a gradient background by creating a measure that returns a variety of results and displays approximate background colors based on the results.
If you think this is possible, you can take a look at my solution.
Here is the test data I created.

vjtianmsft_0-1714445049622.png

I have created a table of dates and now I am calculating the number of days between the dates in the table and the current time by creating a measure.
Multiple results are created in this measure.

vjtianmsft_1-1714445073958.png

Here is the DAX code.

MEASURE =
VAR tableDate =
    MIN ( 'YourTable'[t_Date] )
VAR nowData =
    TODAY ()
VAR differ =
    DATEDIFF ( nowData, tableDate, DAY )
RETURN
    SWITCH (
        TRUE (),
        -30 <= differ
            && differ <= 30, "red",
        30 < differ
            && differ <= 60, "red-orange",
        60 < differ
            && differ <= 183, "orange",
        183 < differ
            && differ <= 365, "yellow",
        differ > 365, "green",
        ""
    )

vjtianmsft_2-1714445142017.png

Manually simulate a color gradient by setting several colors of the gradient from the multiple results returned by measure.

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.

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

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.