Forum Discussion
Indexing with a custom increment
Hello, I'm trying to find an M formula that with increase the increment by 1 after every 3 rows. For example:
Row # Index
1 1
2 1
3 1
4 2
5 2
6 2
7 3
8 3
9 3
Thanks very much for any suggestions!
Hi Anonymous
You can achieve this by the GUI without any custom formula. Follow below steps!
First add an Index column starting from 1.
Then divide Index column by 3. From Transform tab > (Number Column) Standard > Divide.
Finally round up Index column. Transform > (Number Column) Rounding > Round Up.
Anyway, if you want a single M formula to get the same result, you can combine above three steps into one step. Paste below code into the formula bar and modify previous step name.
= Table.TransformColumns(Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type), {{"Index", each Number.RoundUp(_ / 3), type number}})Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.- Anonymous4 years ago
Thanks very much - this is a great solution!
4 Replies
- AnonymousNot applicable
This would work. If your prior step is named LastStep, add a new step. In the formula bar, type:
= Table.AddColumn(LastStep, "NewIndex", each if Number.Mod([Index], 3) = 0 then [Index]/3 else null)
Then you can use Fill Up function in the GUI for the missing values.
--Nate
- AnonymousNot applicable
Thank you very much!
- v-jingzhangCommunity Support
Hi Anonymous
You can achieve this by the GUI without any custom formula. Follow below steps!
First add an Index column starting from 1.
Then divide Index column by 3. From Transform tab > (Number Column) Standard > Divide.
Finally round up Index column. Transform > (Number Column) Rounding > Round Up.
Anyway, if you want a single M formula to get the same result, you can combine above three steps into one step. Paste below code into the formula bar and modify previous step name.
= Table.TransformColumns(Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type), {{"Index", each Number.RoundUp(_ / 3), type number}})Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.- AnonymousNot applicable
Thanks very much - this is a great solution!