<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic For Loop in Quick Measures Gallery</title>
    <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/For-Loop/m-p/637531#M319</link>
    <description>&lt;P&gt;This is a demonstration on how to emulate a traditional For loop in DAX. For further explanation, see this article:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Community-Blog/For-and-While-Loops-in-DAX/bc-p/637511" target="_blank"&gt;https://community.powerbi.com/t5/Community-Blog/For-and-While-Loops-in-DAX/bc-p/637511&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;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]&amp;lt;=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])&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="reportid hidden"&gt;eyJrIjoiMmZkY2UzOWQtZmQxYi00ZTRiLTg1M2QtZjllZmVjNWQ0ZmNjIiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Mar 2019 19:51:48 GMT</pubDate>
    <dc:creator>Greg_Deckler</dc:creator>
    <dc:date>2019-03-05T19:51:48Z</dc:date>
    <item>
      <title>For Loop</title>
      <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/For-Loop/m-p/637531#M319</link>
      <description>&lt;P&gt;This is a demonstration on how to emulate a traditional For loop in DAX. For further explanation, see this article:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Community-Blog/For-and-While-Loops-in-DAX/bc-p/637511" target="_blank"&gt;https://community.powerbi.com/t5/Community-Blog/For-and-While-Loops-in-DAX/bc-p/637511&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;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]&amp;lt;=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])&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="reportid hidden"&gt;eyJrIjoiMmZkY2UzOWQtZmQxYi00ZTRiLTg1M2QtZjllZmVjNWQ0ZmNjIiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2019 19:51:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/For-Loop/m-p/637531#M319</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2019-03-05T19:51:48Z</dc:date>
    </item>
  </channel>
</rss>

