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
 

Some videos you may like

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

anvg

Active Member
Joined
Feb 14, 2012
Messages
478
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,
 

Mathexcel

New Member
Joined
Jun 22, 2017
Messages
36
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
 

sandy666

Well-known Member
Joined
Oct 24, 2015
Messages
5,379
like this?
rollover.png
 

Watch MrExcel Video

Forum statistics

Threads
1,099,369
Messages
5,468,217
Members
406,574
Latest member
HeinrichPaul

This Week's Hot Topics

Top