---
schema_version: "1"
id: a3a0d215b8bba3997ba70233223ee82c64085389ba59335e58b0aa709efc65d8
title: Set Up Complex Conditional Formatting
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/analytics/264-0-0/bi_dashboards_condformat_complex.md
canonical_url: https://help.salesforce.com/s/articleView?id=analytics.bi_dashboards_condformat_complex.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 361f8f1f7e089dc712bfee239193dd40c75769060d6c9c7a197209b920cafd50
description: You can set up conditions based on a single reference column in the widget properties. However, sometimes, you have to create more complex conditions. To set up rules based on multiple reference columns for number and table widgets, use SAQL.
products:
  - CRM Analytics
  - Cross Cloud
release: "264"
---
# Set Up Complex Conditional Formatting

You can set up conditions based on a single reference column in the widget properties. However, sometimes, you have to create more complex conditions. To set up rules based on multiple reference columns for number and table widgets, use SAQL.

1. Set up the conditions in the SAQL query. Define the rules and output the colors to a new column. Specify the colors in hex codes (like #CCCC00) or RGB codes (like rgb(255,255,255) or rgba(255,255,255,0)).
    
    For example, the following query specifies the rule and outputs the hex color code for each condition in the “FormatColor” column.
    
    ```
    "query": "q = load "Sample_Superstore_with_Goals";\n 
        result = group q by 'Segment';\n 
        result = foreach result generate 
            q.'Segment' as 'Segment', 
            sum(q.'Discount') as 'Discount', 
            sum(q.'Profit') as 'Profit', 
            sum(q.'Quantity') as 'Quantity', 
            sum(q.'Sales') as 'Sales', 
            (case 
                when Segment == "Consumer" and sum(q.'Discount') >= 1000 then "#008000" 
                when Segment == "Consumer" and sum(q.'Discount') < 1000 then "#CCCC00" 
                when Segment == "Corporate" and sum(q.'Discount') >= 500 then "#008000" 
                when Segment == "Corporate" and sum(q.'Discount') < 500 then "#CCCC00" 
                when Segment == "Home Office" and sum(q.'Discount') >= 200 then "#008000" 
                when Segment == "Home Office" and sum(q.'Discount') < 200 then "#CCCC00" 
                else "#000000" end) as 'FormatColor';\n 
        result = order result by ('Sales' desc);\n 
        result = limit result 2000;", 
    ```
2. To apply the text color to the Sales table column, select the new color column (“FormatColor”) in the Reference Column widget property and then select **Use Color in Reference Column** in the Coloring Method option.
    
    The following example conditionally colors the text in the Sales table column based on the logic used to determine the color in the “FormatColor” reference column.
    
    ![Conditional formatting for the Customer Name column uses the color referenced in the "Color" column.](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-analytics-bi-264-0-0-production-enus/ec791473-f5b4-4f64-a656-9104f455d966/bi/images/bi/bi_dashboards_condFormat_complexCase.png)