Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric certified for FREE! Don't miss your chance! Learn more
Your file has been submitted successfully. We’re processing it now - please check back in a few minutes to view your report.
This is a demonstration on how to emulate a traditional For loop in DAX. For further explanation, see this article:
https://community.powerbi.com/t5/Community-Blog/For-and-While-Loops-in-DAX/bc-p/637511
For Loop = // Provide some starting values VAR __n = 5 VAR __sum = 10 // Generate a "loop table", this will emulate a for loop for i=1 to some number VAR __loopTable = GENERATESERIES(1,__n) // Add in our calculated sum, emulating calculations done as iterations over the loop VAR __loopTable1 = ADDCOLUMNS(__loopTable,"__sum",SUMX(FILTER(__loopTable,[Value]<=EARLIER([Value])),[Value])) // Determine our MAX interation, the maximum value for "i" VAR __max = MAXX(__loopTable1,[Value]) RETURN // Return the value associated with the maximum value of "i" which is the last iteration in our "loop" MAXX(FILTER(__loopTable1,[Value]=__max),[__sum])
eyJrIjoiMmZkY2UzOWQtZmQxYi00ZTRiLTg1M2QtZjllZmVjNWQ0ZmNjIiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9