Forum Discussion
BlueSky
6 years agoHelper I
How to make this DAX code more efficient (less duplication).
The following table expression is working fine (it's to create exponential growth data for the Covid-19 virus, based on the virus doubling every x days.). I'm still learning PowerBI and I'm st...
- Anonymous6 years ago
EVALUATE var __rates = SELECTCOLUMNS( {.5, 0.333, 0.25, 0.2}, "GrowthRate", [Value] ) var __upperLimit = 10 var __output = GENERATE( __rates, var __currentRate = [GrowthRate] return ADDCOLUMNS( GENERATESERIES(1, __upperLimit, __currentRate ), "Days", round( [Value] / __currentRate + 1, 0), "Deaths", round(__upperLimit * POWER(2, [Value] ), 0 ), "Country", COMBINEVALUES( " ", // delimiter "Every", round(1 / __currentrate, 0), "days" ), "KeyFactToDimStartEnd", COMBINEVALUES( " ", "Every", round(1 / __currentrate, 0), "days", "-", round( [Value] / __currentRate + 1, 0 ) ) ) ) return __outputBest
D
Anonymous
6 years agoNot applicable
EVALUATE
var __rates =
SELECTCOLUMNS(
{.5, 0.333, 0.25, 0.2},
"GrowthRate",
[Value]
)
var __upperLimit = 10
var __output =
GENERATE(
__rates,
var __currentRate = [GrowthRate]
return
ADDCOLUMNS(
GENERATESERIES(1, __upperLimit, __currentRate ),
"Days",
round( [Value] / __currentRate + 1, 0),
"Deaths",
round(__upperLimit * POWER(2, [Value] ), 0 ),
"Country",
COMBINEVALUES(
" ", // delimiter
"Every",
round(1 / __currentrate, 0),
"days"
),
"KeyFactToDimStartEnd",
COMBINEVALUES(
" ",
"Every",
round(1 / __currentrate, 0),
"days",
"-",
round( [Value] / __currentRate + 1, 0 )
)
)
)
return
__output
Best
D
BlueSky
6 years agoHelper I
Anonymous thanks so much for writing this, it'll really help my learning! 🙂