Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power BI Table Union Change Color: Formatting Guide

· 7 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To change the color of a table union in Power BI, you must use Conditional Formatting based on a column that distinguishes the original data sources. Because a union (Append) combines multiple tables into one single table, Power BI treats the result as a uniform dataset; you cannot simply click a "color" button for one of the original tables. Instead, you create a DAX measure or use a source column to tell the Table or Matrix visual which rows should be which color.

What You'll Need

  • Power BI Desktop installed and open.
  • Two or more tables that have been combined using the "Append Queries" feature in Power Query.
  • A "Source" or "Category" column in your appended table that identifies which original table the data came from.
  • Basic familiarity with the Format pane in the Report view.

Step-by-Step

  1. Identify your Source Column: Before moving to the report view, ensure your appended table has a column that labels the data. If you didn't add one during the Append process in Power Query, go back to Transform Data. In Power Query, go to each original table and use Add Column > Custom Column. Name it "Source" and give it a text value (e.g., "Table A" for the first table and "Table B" for the second). Now, when you Append them, this column will persist in the unioned table.
  2. Create the Table Visual: In the Report view, select the Table icon from the Visualizations pane. Drag the fields from your unioned table into the Columns bucket. Ensure the "Source" column is included if you want to see the labels, or keep it hidden if you only want the colors to represent the source.
  3. Open Conditional Formatting: In the Visualizations pane, look at the Columns section. Right-click (or click the small down arrow) on the specific field you want to color. Navigate to Conditional formatting > Background color. Note that menu labels may differ slightly depending on your version of Power BI Desktop.
  4. Configure the Format Style: In the Background color dialog box, change the Format style dropdown from "Gradient" to "Field value". This is the most precise way to handle union colors because it allows you to define exact hex codes via DAX.
  5. Create a Color Measure: Since you chose "Field value", you now need a measure that tells Power BI which color to use. Click New Measure in the Home tab and enter a DAX formula similar to this: In this example, "#ADD8E6" is light blue and "#FFB6C1" is light pink. The final "#FFFFFF" is the default white for any rows that don't match.
  6. Apply the Measure: Go back to the Background color dialog box. In the What field should we base this on? dropdown, search for and select the SourceColor measure you just created. Click OK.
  7. Repeat for Other Columns: Conditional formatting in Power BI is applied per column. To make the entire row appear colored based on the union source, you must repeat steps 3 through 6 for every single column present in your table visual.
  8. Adjust Font Colors: If your background colors are dark, your black text may be hard to read. Repeat the process above, but instead of selecting "Background color", select Conditional formatting > Font color and use the same SourceColor measure (or create a separate SourceFontColor measure with contrasting hex codes).

Common Mistakes

One of the most frequent errors is attempting to use the "Gradient" format style for unioned data. Gradients are designed for numeric values (e.g., low sales are red, high sales are green). Because a table union is usually distinguished by a text category (the source table name), a gradient will not work. Always use "Field value" for categorical color coding.

Another common mistake is forgetting to add the source identifier in Power Query before the append. If you append three tables and they all have the same column names but no "Source" column, the resulting table is a seamless blend. You will have no way to tell the DAX measure which row belonged to which original table, making it impossible to color them differently. You must return to the Power Query Editor and add a custom column to each source table before performing the Append.

Users also often forget that formatting is column-specific. It is a common frustration to apply the color to the "Revenue" column and wonder why the "Date" column remains white. In Power BI, there is no "Row Format" setting that applies a single rule to the entire horizontal line; you must apply the conditional formatting rule to every individual field in the visual.

Tips

To make your report more maintainable, avoid hard-coding hex codes directly into multiple measures. Instead, create one master "Color Palette" table or a set of hidden measures that define your corporate colors. This way, if you decide to change "Table A" from blue to green, you only have to update the hex code in one place rather than updating every single conditional formatting rule across multiple pages.

For a cleaner look, you can hide the "Source" column from the visual while still using it for the formatting logic. You do not need a field to be visible in the table for the DAX measure to reference it. This allows you to visually distinguish the data sources through color without taking up valuable horizontal screen real estate with a redundant text column.

If you are dealing with a very large number of tables in your union (e.g., 10+ different sources), the SWITCH function can become cumbersome. In these cases, consider creating a separate mapping table that contains two columns: "Source Name" and "Hex Code". Create a relationship between your unioned table and this mapping table. Then, your conditional formatting can simply point to the "Hex Code" column in the mapping table, eliminating the need for complex DAX measures.

Troubleshooting

If the colors are not appearing, first check that your DAX measure is returning a valid hex code. A valid hex code must start with a hash symbol (e.g., #FFFFFF). If you omit the #, Power BI will not recognize the string as a color and will default to the standard background.

If the color is appearing in some rows but not others, verify the exact spelling of the values in your "Source" column. DAX is sensitive to trailing spaces or slight misspellings. For example, "Table A" is not the same as "Table A ". Use the TRIM() function in Power Query to remove any accidental whitespace from your source labels.

If the visual becomes extremely slow after applying conditional formatting to many columns, it is likely because the DAX measure is being calculated for every single cell in the table. To optimize, ensure that the "Source" column is indexed or that you are using a simple mapping table relationship rather than a complex SWITCH statement with many conditions.

If the "Field value" option is grayed out or missing, ensure that the field you are formatting is not a complex calculated column that conflicts with the formatting logic. Try creating a simple measure first to see if the option reappears.

Frequently Asked Questions

Can I change the color of the unioned table using the standard Theme settings?

No. Theme settings apply to the visual as a whole (e.g., all zebra stripes or all headers). To differentiate rows based on which table they came from in a union, you must use conditional formatting.

Do I have to use DAX for this, or is there a simpler way?

You can use the "Rules" format style instead of "Field value". In the Rules menu, you can say "If value is Table A, then color is Blue." This is easier for 2-3 colors, but DAX is more scalable and precise for professional reports.

Will this formatting stay if I refresh the data?

Yes. As long as the "Source" column exists in the data being refreshed, the conditional formatting rules will continue to apply to the new rows automatically.

Can I color the rows based on a value from a different table?

Yes, provided there is a relationship established in the Model view. You can write a DAX measure using RELATED() to fetch a color code from a lookup table based on the unioned table's ID.

Why is my table showing a gradient instead of solid colors?

This happens when the Format style is set to "Gradient". Change the style to "Field value" or "Rules" in the conditional formatting menu to achieve solid, distinct colors for your unioned sources.