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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
moltra_1
Regular Visitor

using IF in Power query

I am trying to run the below M code in Power query,

 

 

(ADGroup as text) as list =>

let

    runCount = 1,

    getad = (parent as text) as list =>

            let  

                runCount = runCount + 1,

                childern = fctGetADGroupGroups(parent),

                Ad = List.Combine({{parent}, List.Accumulate(childern, {}, (a , b) =>  List.Combine({a,@getad(b)}))})

            in

            Ad,

            Result =  if runCount < 5 then getad( ADGroup ) else Result

in

   Result

 

.Without the if statement I am getting the error "Evaluation resulted in a stack overflow and cannot continue.

I am trying to pull up the recursive Active Directory groups.

 

3 REPLIES 3
Anonymous
Not applicable

Hi @moltra_1 ,

 

It seems that this if statement is controlling the depth of the recursion. Why would you want to remove it?

Try increasing or decreasing the number in the if statement.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

I cannot get the IF statement to work.  I am trying to put it in there to control the recursive depth.  I should have been more clear in my initial post.

 

With the IF statement, I am getting no Syntax errors, but get the following error.  

 

An error occurred in the ‘’ query. Expression.Error: The name 'Result' wasn't recognized. Make sure it's spelled correctly.

moltra_1
Regular Visitor

Here is where I got the power querys from.  using power query to recursively extract data from Active Directory 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.