Skip to content

Commit 67a0bd8

Browse files
authored
Update Conditional-Colors-Dax-CheatSheet.md
1 parent a863979 commit 67a0bd8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

source-dax/Conditional-Colors-Dax-CheatSheet.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
## Conditional format using a gradient
2+
```ts
3+
[ HSL Hue from Sales ] =
4+
// simpler version, scales hue from 0 degrees to maxHue
5+
6+
// outputs a gradient like:
7+
// hsl( 0, 80%, 78%)
8+
// hsl( 40, 80%, 78%)
9+
// hsl( 160, 80%, 78%)
10+
var hue_1 = 0
11+
var hue_2 = 40
12+
var hue_3 = 160
13+
var maxHue = 160
14+
15+
VAR CurrentValue = SELECTEDVALUE( Sale[Value], 0 )
16+
VAR MinValue = CALCULATE( MIN(Sale[Value]), All( Sale[Value] ) )
17+
VAR MaxValue = CALCULATE( MAX(Sale[Value]), All( Sale[Value] ) )
18+
// Can this ALL() be rewritten to run faster?
19+
20+
var relativeValue =
21+
DIVIDE(
22+
CurrentValue - MinValue,
23+
MaxValue - MinValue,
24+
0
25+
)
26+
27+
// outputs the color string: "hsl( 60, 80%, 78% )"
28+
var renderInt = format( (relativeValue * maxHue), "#,0", "en-us" )
29+
var finalColor = "hsl( " & renderInt & ", 80%, 80%)"
30+
return finalColor
31+
```
32+
133
## Static Measure to Test Syntax
234

335
To use one, choose conditional formatting:

0 commit comments

Comments
 (0)