Skip to content

Commit 2b8a61e

Browse files
authored
Create ConditionalColors-UseMinMax-For-Gradients.dax
1 parent 67a0bd8 commit 2b8a61e

File tree

1 file changed

+24
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)