Forum Discussion
smpa01
2 years agoCommunity Champion
DAX forLoop
AlexisOlson is it possible to replicate a forLoop in DAX. I need a forLoop that works in filter context. I am not able to find anything that can do the following in DAX.
let
src=Table...
- 2 years ago
Custom DAX = VAR i = [index] VAR b = ADDCOLUMNS ( FILTER ( Query1, [index] >= i ), "g", VAR i2 = [index] RETURN SUMX ( FILTER ( Query1, [index] >= i && [index] <= i2 ), [Value] ) ) RETURN CONCATENATEX ( FILTER ( b, [g] <= 100 ), [row], "-" )
smpa01
2 years agoCommunity Champion
You can use the code from snippet to get the sample data.
lbendlin
2 years agoSuper User
Custom DAX =
VAR i = [index]
VAR b =
ADDCOLUMNS (
FILTER ( Query1, [index] >= i ),
"g",
VAR i2 = [index]
RETURN
SUMX ( FILTER ( Query1, [index] >= i && [index] <= i2 ), [Value] )
)
RETURN
CONCATENATEX ( FILTER ( b, [g] <= 100 ), [row], "-" )
- lbendlin2 years agoSuper User
Here's a slightly optimized version
Custom DAX = VAR i = [index] VAR f = FILTER ( Query1, [index] >= i ) VAR g = ADDCOLUMNS ( f, "rt", VAR i2 = [index] RETURN SUMX ( FILTER ( f, [index] <= i2 ), [Value] ) ) RETURN CONCATENATEX ( FILTER ( g, [rt] <= 100 ), [row], "-" )