M Loop that does its action on a table and returns table

Russell Hauf

MrExcel MVP
Joined
Feb 10, 2002
Messages
1,611
So I'm pretty new to M / Power Query, and I am trying to do something similar to this post

I have a function that does operations on a table and it works, we will call it TableOps1. I'm trying to write TableOps2 that calls TableOps1 while there are still Lists or Records in my table (I also have a function that returns the names of the fields with a particular type, called GetAllColumnsWithType)...TableOps2 is NOT working. :)

Here's what I've tried so far (and a few variations of this) - this iteration seems to just go into an infinite loop (no syntax errors or anything):

Code:
let 
    TableOps2 = (inTable as table) as table => 
let
    tblCpy = Table.Buffer(inTable),
    
    Loop = 
        List.Generate(
            ()=> [Table = tblCpy,
                  Counter = 1, 
                  Continue = List.Count(GetAllColumnsWithType(tblCpy, type list)) + List.Count(GetAllColumnsWithType(tblCpy, type record)) > 0],
            each [Continue],
            each [Table = TableOps1(tblCpy),
                Continue = [Counter] < 8 or (List.Count(GetAllColumnsWithType(Table, type list)) + List.Count(GetAllColumnsWithType(Table, type record)) > 0),
                Counter = [Counter] + 1],
            each [Table]),
    TableWithData = if List.IsEmpty(Loop) then tblCpy else List.Last(Loop)
in 
    TableWithData
in    
    TableOps2
Any ideas what I'm doing wrong / suggestions?

Thanks in advance!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,213,532
Messages
6,114,176
Members
448,554
Latest member
Gleisner2

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