Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by watching the DP-600 session on-demand now through April 28th.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
Dear M-query kings and queens,
I made an recursion function as followed:
(in_boekjaar as text) as table=>
let
in_Table = #table({},{}),
in_loop = 0,
Companies = GetCompanies("10", "0"), // in dit blok wordt het totaal aan administraties opgehaald om het maximaal aantal loopts te berekenen, zie ook de variable TotalLoops
companies = Companies[companies],
#"Converted to Table" = Table.FromList(companies, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
ListOfCompanies = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"companyId", "accountingSystem", "totalDocumentsToAuthorize", "name", "email", "_links", "externalId", "language", "extraData", "hasAccess"}, {"Column1.companyId", "Column1.accountingSystem", "Column1.totalDocumentsToAuthorize", "Column1.name", "Column1.email", "Column1._links", "Column1.externalId", "Column1.language", "Column1.extraData", "Column1.hasAccess"}),
TotalLoops = Table.RowCount(ListOfCompanies),
in_iD = ListOfCompanies[Column1.companyId]{0},
RecFunction = (Id as text, boekjaar as text, loop as number, optional paraTable) as table=>
let
Source = GetTransactions(Id, boekjaar),
Extract1 = Source[transactions],
Extract2 = Table.FromList(Extract1, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
CurrentLoop = loop +1,
IdOfCompany = if CurrentLoop -1 = 0
then ListOfCompanies[Column1.companyId]{0}
else ListOfCompanies[Column1.companyId]{CurrentLoop},
MergedTable = if paraTable = null
then Table.Combine({#table({},{}),Extract2})
else Table.Combine({paraTable,Extract2}),
Result = if CurrentLoop >= TotalLoops
then MergedTable
else @RecFunction(IdOfCompany,in_boekjaar, CurrentLoop, MergedTable)
in
Result,
output = RecFunction(in_iD, in_boekjaar, in_loop, in_Table)
in
output
It works as followed:
1. In the first part i call another function that gives me the total amount of companies that i want to retrieve. I put this number in the "TotalLoops" variable.
2. Then the recursion function loops through the companies wich i got earlier by incrementing the "CurrentLoop" value by 1 every company it loops trough and merges the tables of each company to one table.
But my incrementor doenst work properly. If i put my max companies list to for example 2 (so i only get 2 iterations) the result gives me the table of only the first company. I checked if there was data on the second company and there was so im doing something wrong.
Anyone can help me out?
Solved! Go to Solution.
Hi @dvdbroek
Your counter is working, but this one, you never get the list{1}, you go {0} then {2}
IdOfCompany = ListOfCompanies[Column1.companyId]{loop},
Hi @dvdbroek
Your counter is working, but this one, you never get the list{1}, you go {0} then {2}
IdOfCompany = ListOfCompanies[Column1.companyId]{loop},
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 4 | |
| 4 |