Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
msksenthil
Helper III
Helper III

Power Query Loop issue

I would like to create the loop and concatenate the list records in power query function but I'm getting error. 

 

M-Code

(loop as number, T1 as table, CurString as any) => let
CurrentLoop = loop + 1,
T1ColumnCount = 5,
T1ColumnValues = Table.ColumnNames(T1),
CurrentString =if (CurrentLoop = 0) then Text.From(T1ColumnValues{CurrentLoop}) else Text.From(CurString) & Text.From(T1ColumnValues{CurrentLoop}),
OutputString = if (CurrentLoop = T1ColumnCount) then CurrentString else @Query2(CurrentLoop, T1, CurrentString)
in
OutputString

 

Error:

Expression.Error: There weren't enough elements in the enumeration to complete the operation.
Details:
[List]

 

Many thanks in advance

4 REPLIES 4
mahoneypat
Employee
Employee

I suspect this is due to the fact that counting in power query starts at zero.  when you get to loop = 5, you are actually pulling the name of the 6th column, which doesn't exist.

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Bingo! It's working great. But when I make it dynamic like "T1ColumnCount =Table.ColumnCount(T1)" it's showing the below error

 

Expression.Error: There weren't enough elements in the enumeration to complete the operation.
Details:
[List]

Fowmy
Super User
Super User

@msksenthil 

What is @Query2 in this context?

Can you share the complete file after removing confidential data?

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy 

Query2 is the own function name.

 

Sorry I couldn't attach the pbix. 

 

msksenthil_0-1621511613658.pngmsksenthil_1-1621511627966.png

Table format

msksenthil_2-1621511650727.png

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors