Split table in multiple ranges with Table.PositionOf and Occurrence.All

ooptennoort

Board Regular
Joined
Mar 29, 2021
Messages
67
Office Version
  1. 365
Platform
  1. Windows
I need to split a table into a range everytime Table.PositionOf finds the "Marker word". It works when using only 1 Occurence (.First or .Last) but .All produces more than 1 number in the list and Table.Range cannot deal with this.

= Table.Range(Source,(Table.PositionOf(Source,[Column1="Marker word"],Occurrence.All,"Column1")),5)

How do I get this to work? In other words, how do I get Table.Range to work on each number in a list of more than one number???? Or rather, how do I "convert a value of type List to type Number" in this context i.e. producing multiple ranges (ideally appended)?

Somehow a recursive function or loop (is there a difference?) would maybe work. Or perhaps a let with some variable, but I still lack M code knowlegde.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
AlienSx from PBI forum came up with a very simple and elegant solution!!

positions = List.Buffer(Table.PositionOf(Source,[Column1="Marker word"],Occurrence.All,"Column1")),
ranges = Table.Combine( List.Transform(positions, each Table.Range(Source, _, 5)) )
 
Upvote 0
Solution

Forum statistics

Threads
1,223,364
Messages
6,171,646
Members
452,415
Latest member
mansoorali

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