Here is my solutions. A βbasicβ one with which I got some problems however, a more complicated one with a parameter table containng factors and formatting.
Solution 1:
FormattedSales =
VAR __Sales = SUM(Data[Dollar Amount])
VAR __Format = SWITCH(TRUE,
__Sales < power(10, 3), "$0",
__Sales < power(10, 6), "$0.0 K",
__Sales < power(10, 9), "$0.0 M",
"$0.0 B"
)
VAR __Ratio = SWITCH(TRUE,
__Sales < power(10, 3), 1,
__Sales < power(10, 6), power(10, 3),
__Sales < power(10, 9), power(10, 6),
power(10, 9)
)
RETURN FORMAT(__Sales/__Ratio, __Format)
Solution 2:
A table containing the parameters:
TableFormat = {
(-1, 1, "$0.0"),
(1000, 1000, "$0.0 K"),
(1000000, 1000000, "$0.0 M"),
(1000000000, 1000000000, "$0.0 B")
}
And the formula using it:
FormattedSales With Table =
VAR __Sales = SUM(Data[Dollar Amount])
VAR __Table = TOPN(1, FILTER(TableFormat, TableFormat[Threshold] < __Sales), TableFormat[Factor], DESC) // filtering the table to lines < sales, keeping the top 1
VAR __Ratio = MINX(__Table, TableFormat[Factor]) //getting the ratio
VAR __Format = MINX(__Table, TableFormat[FormatString]) //and the format string
RETURN FORMAT(__Sales/__Ratio, __Format)