Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Loop within a loop

Hi, everyone.

 

I'm newer to Power BI, and I'm trying to mash 2 functions together to execute a loop within a loop.

  1. My first function, GetAllFolders, generates a table with 2 columns: FolderID and FolderName
  2. My second function, GetAllQueuesinFolder, generates a table with 3 columns: QueueName, OrganizationalUnitId, and ID.

What I need is for a table to be produced that takes each row of the table from GetAllFolders and loops through each row to GetAllQueuesInFolder for each folder. In the end, I want a table that has a row for each queue in all the folders. So, if each of my 4 folders has 2 queues, then I want a table with 5 columns (FolderID, FolderName, QueueName, OrganizationalUnit, and ID) and 8 rows, one for each queue.

 

Any ideas how to create this function?

  • =Table.FromRecords(List.TransformMany(Table.ToRecords(GetAllFolders(),each Table.ToRecords(GetAllQueuensinFolder([FolderName])),(x,y)=>x&y))

3 Replies

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Icon for Community Champion rankCommunity Champion

    =Table.FromRecords(List.TransformMany(Table.ToRecords(GetAllFolders(),each Table.ToRecords(GetAllQueuensinFolder([FolderName])),(x,y)=>x&y))

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks for your help.
      I pasted your function in Power BI like so:

      And clicked "Invoke" and got this error:

       

      Any ideas? Thanks again.

       

      EDIT:

      I think I wasn't putting the function in the editor correctly. I entered it like this now, and I still got the same error as above.

       

       

       

      Thanks so much for your help. I am just learning this language.

      • wdx223_Daniel's avatar
        wdx223_Daniel
        Icon for Community Champion rankCommunity Champion

        my code just a example, you need complete it in your real circumstance.

        GetAllFolders() and GetAllQueuensinFolder() may have some arguements to fill.