PowerQuery > create a modulo sequence

Mathexcel

New Member
Joined
Jun 22, 2017
Messages
36
Hi

I am trying to consolidate about 30 documents into this one master database with Power Query.
When expanding all my tables, it seems like the Item column isn't populated for some of the documents.

The Occupancy(%) column is organised in a sequence of 5 items for 3 KPIs.

> I would like this sequence to repeat throughout the entire column.

Below is a picture of my data sample in PQ; I have about 10k rows. As you can see, the sequence breaks from row 16. Row 16 should start with Occupancy (%).
1579081251887.png


I was thinking of using a modulo, but I don't know how to create a sequence so that it repeats:
The First one to get the KPIs > {1,1,1,1,1,2,2,2,2,2,3,3,3,3,3}. 1 will be replaced with Occupancy (%), 2 with Average Daily Rate etc...
the Second one with {1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,....}. The 5 will be replaced with Change vs prior year (%)

Keen to learn a new approach to solve this issue.

I hope it makes sense. Many thanks in advance for your time.
Best,
MattExcel
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi.
Try
Code:
let
    Source = Table.FromColumns({{1..100}}, {"Column1"}),
    AddId = Table.AddIndexColumn(Source, "id", 0),
    Add1_5 = Table.AddColumn(AddId, "1..5", each Number.Mod([id], 5) + 1, Int64.Type),
    Add1__3Only = Table.AddColumn(Add1_5, "1 to 3", each let n = Number.IntegerDivide([id], 5) in if n > 2 then null else n + 1, Int64.Type)
in
    Add1__3Only
Regards,
 
Upvote 0
Smooth, thanks for showing me the mod way!

The sequence works well but doesn't roll over. How do I get start it back to 1?

1579824250597.png


Many thanks in advance.
MattExcel
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top