> For the complete documentation index, see [llms.txt](https://atd-dts.gitbook.io/tpw-staff/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://atd-dts.gitbook.io/tpw-staff/power-bi/power-query-and-dax-formulas/conditional-format-using-dax.md).

# Conditional Format using DAX

This goes step by step into setting up conditional formatting using new columns/measures in DAX

## Query Viewer

Pull the distinct values you wish to conditional format

```dax
DISTINCT(SELECTCOLUMNS('Table','Column Name or Measure'))
```

### DAX

Create a calculated column or measure using the `SWITCH()` formula. You can set it to background color, font clor, icons, and/or Web URL!

#### Column

```dax
Status Colors = 
VAR _s = 'Table'[Column]

RETURN
SWITCH(
	TRUE(),
	_s = "Closed","#ADADAD",
	_s = "Duplicate (closed)", "#777777",
	_s ="Open", "#E41A1C",
	_s = "Work In Progress", "#367DB7",
	_s = "Duplicate (open)", "#E41A1C",
	_s = "New", "#E41A1C"
)
```

#### Measure

```dax
Status Colors = 
VAR _s = [Measure]

RETURN
SWITCH(
	TRUE(),
	_s = "Closed","#ADADAD",
	_s = "Duplicate (closed)", "#777777",
	_s ="Open", "#E41A1C",
	_s = "Work In Progress", "#367DB7",
	_s = "Duplicate (open)", "#E41A1C",
	_s = "New", "#E41A1C"
)
```

## Cell Elements

On tables and matrix visuals, you can set the field value to the value of a column or measure

<figure><img src="https://1391570612-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M2EDlSmB3f_vryzLEhZ%2Fuploads%2FB8n08sWixF30XqGeBhkz%2Fimage.png?alt=media&amp;token=b8a3ec91-9b67-4050-a264-46d200dbeec4" alt=""><figcaption><p>Example conditional format</p></figcaption></figure>
