Forum Discussion
datasith
Jun 14, 2021Copper Contributor
Counter variable in Power Query each loop
/* [Index] and [Initial Stock] are columns in the Table that I can reference. */
/* I'm curious how to have an "i" variable accessible in the M code */
#"Added Index II" ...
- Jun 21, 2021
Hi datasith,
This series article might put you back on track:
https://www.data-insights.de/loops-in-m-recursion/
https://www.data-insights.de/loops-in-m-language-list.generate/
https://www.data-insights.de/part-3-for-next-loop-using-list-accumulate-in-m-for-power-query/
Hope that helps you.
cheers
SergeiBaklan
Jun 14, 2021Diamond Contributor
That will be easier if you explain what shall be in column Index II. If index in it for each zero Initial Stock shall be the same as for the previous non-zero, you may create column with
... each if [Initial Stock] > 0 then [Index] else null
and fill down after that.