Forum Discussion
Index cycles in DAX
- 3 years ago
Hi mangaus1111
** EDIT - I see HotChilli beat me to it. Sorry it took me a while to respond as I had to modify and test my code in between getting kids off to school. HotChilli answered before me but I'll leave this here as an alternative.
You can use List.Generate. I modified code I wrote to calculate Grouped Running Totals
(values as list) as list => let Result = List.Generate ( ()=> [ Flips = 1, i = 0 ], each [i] < List.Count(values), each try if values{[i]} = values{[i] + 1} then [Flips = [Flips] , i = [i] + 1] else [Flips = [Flips] + 1, i = [i] + 1] otherwise [i = [i] + 1] , each [Flips] ) in ResultRegards
Phil
Hi mangaus1111
** EDIT - I see HotChilli beat me to it. Sorry it took me a while to respond as I had to modify and test my code in between getting kids off to school. HotChilli answered before me but I'll leave this here as an alternative.
You can use List.Generate. I modified code I wrote to calculate Grouped Running Totals
(values as list) as list =>
let
Result = List.Generate
(
()=> [ Flips = 1, i = 0 ],
each [i] < List.Count(values),
each try
if values{[i]} = values{[i] + 1}
then [Flips = [Flips] , i = [i] + 1]
else [Flips = [Flips] + 1, i = [i] + 1]
otherwise [i = [i] + 1]
,
each [Flips]
)
in
Result
Regards
Phil
Hi PhilipTreacy ,
your solution is simply amazing. Thank you. I feel like now studing advanced M.
Do you know if online there are some free resources for this kind of queries in M?
- PhilipTreacy3 years ago
Super User
No worries mangaus1111
Sorry I can't recommend any single source to learn M. There are lots of good places on the net, you'll just have to work through them and see what clicks with you.
I'm the same as most I guess, lots of Googling, writing code for hours figuring stuff out and quite a lot of banging my head against the wall with things like List.Generate. I wish there was a debugger for M.
Cheers
Phil