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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
MatheusLPS
Helper I
Helper I

List.Generate calling outside function

Hello,

 

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.

 

 

let

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

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

		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
	areas_geradas

in search_area

 

2 REPLIES 2
v-yulgu-msft
Microsoft Employee
Microsoft Employee

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.

 

Thanks,

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?

Thanks.

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

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.