Showing results for 
Search instead for 
Did you mean: 
Helper I
Helper I

List.Generate calling outside function



I made a recursion function with List.Generate. It is working. My question is related the performance.


My goal is to see on a tree the master brach from inner levels. 


My function looks like below. Comments and question on the code.




	search_area  = (area_param) =>  //outside parameter from column table

		Source = (id_param as number) =>
			table_result = Sql.Database("my server", "my data base", [Query="My select query with parameter" & Number.ToText(id_param), CreateNavigationProperties=false]),

		areas_function = List.Generate 
			() => [area_id_f = area_param, name_f = "xx", parent_id_f = 1], //inicital values. Just anything
			each [parent_id_f] <> null,                                     //while my flag is not null
			each                                                            //my question is here. To update my variables, I am calling the outside "Source" function each time. Is it correct?
				area_id_f  = Source([area_id_f]){0}[parent_id],
				name_f = Source([area_id_f]){0}[name],
				parent_id_f = Source([area_id_f]){0}[parent_id]
			each [name_f]                //When my flag is null, return the master branch name

		areas_geradas =  List.Last(areas_function)     //Just the last one

in search_area



Hi @MatheusLPS,


Some experts being experienced in Power Query might provide professional advice for you.


@ImkeF@MarcelBeug, Do you have any comment to this topic? appreciate for your help.



Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Sorry @MatheusLPS, but I cannot follow you here.

Could you please post a link to a sample file where I can follow what you're trying to achieve?


Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

charticulator_carousel_with_text (1).png

Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through May 31st!

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Power BI Dev Camp Session 22 768x460.jpg

Check it out!

Mark your calendars and join us on Thursday, May 26 at 11a PDT for a great session with Ted Pattison!