<?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 Re: Problem with dax formula | Calculate an index with conditional over a period of 8 weeks in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-dax-formula-Calculate-an-index-with-conditional/m-p/3588200#M138498</link>
    <description>&lt;P&gt;Certainly, I can help you with that! It sounds like you want to create an index that is 0 if there has been zero volume for 8 consecutive weeks and 1 if there has been any volume greater than 0 within an 8-week period. Additionally, you want the result to be aggregated over the entire interval for each SAP and date.&lt;/P&gt;&lt;P&gt;You can achieve this using DAX (Data Analysis Expressions) in Power BI. Here's a general approach:&lt;/P&gt;&lt;P&gt;Assuming you have a table named YourTable with columns like SAP, Date, and Volume, you can create a calculated column for your index using the following DAX formula:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I8W =&lt;BR /&gt;VAR CurrentDate = YourTable[Date]&lt;BR /&gt;VAR EightWeeksAgo = CurrentDate - 56 // 8 weeks * 7 days per week = 56 days&lt;/P&gt;&lt;P&gt;RETURN&lt;BR /&gt;IF (&lt;BR /&gt;CALCULATE(&lt;BR /&gt;SUM(YourTable[Volume]),&lt;BR /&gt;FILTER(&lt;BR /&gt;YourTable,&lt;BR /&gt;YourTable[Date] &amp;gt;= EightWeeksAgo &amp;amp;&amp;amp;&lt;BR /&gt;YourTable[Date] &amp;lt;= CurrentDate &amp;amp;&amp;amp;&lt;BR /&gt;YourTable[Volume] &amp;gt; 0&lt;BR /&gt;)&lt;BR /&gt;) &amp;gt; 0,&lt;BR /&gt;1,&lt;BR /&gt;0&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This formula calculates the sum of the volume for the last 8 weeks, and if the sum is greater than 0, it returns 1; otherwise, it returns 0.&lt;/P&gt;&lt;P&gt;Remember to adjust column and table names according to your actual Power BI model.&lt;/P&gt;&lt;P&gt;To get the total sum filtered by each SAP and date, you can use this DAX measure:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TotalVolume = SUMX(FILTER(YourTable, YourTable[I8W] = 1), YourTable[Volume])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This measure calculates the sum of volumes for each SAP and date where the I8W index is 1.&lt;/P&gt;&lt;P&gt;Again, make sure to replace YourTable and column names with your actual table and column names.&lt;/P&gt;&lt;P&gt;These measures and calculated columns can be added to your Power BI report to achieve the desired results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;If this post&amp;nbsp;helps, then please consider&amp;nbsp;Accepting it as the solution&amp;nbsp;to help the other members find it more quickly.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In case there is still a problem, please feel free and explain your issue in detail,&amp;nbsp;It will be my pleasure to assist you in any way I can.&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Dec 2023 06:52:13 GMT</pubDate>
    <dc:creator>123abc</dc:creator>
    <dc:date>2023-12-18T06:52:13Z</dc:date>
    <item>
      <title>Problem with dax formula | Calculate an index with conditional over a period of 8 weeks</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-dax-formula-Calculate-an-index-with-conditional/m-p/3587692#M138472</link>
      <description>&lt;P&gt;Good afternoon, everyone, can you help me?&lt;/P&gt;&lt;P&gt;I made a formula called "I8W" (Index of 8 weeks): which returns me:&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;UL&gt;&lt;LI&gt;0 if any SAP has had 0 volume for 8 weeks in a row&lt;/LI&gt;&lt;LI&gt;1 if any SAP has had a volume greater than 0 within 8 weeks&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;However, as you can see in the image below, it only returns 1 for the last date, I would like the 1 to be counted over the entire interval.&amp;nbsp;I would also like to have the total sum filtered by each SAP and date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;.&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Dec 2023 19:06:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-dax-formula-Calculate-an-index-with-conditional/m-p/3587692#M138472</guid>
      <dc:creator>carddosogabriel</dc:creator>
      <dc:date>2023-12-17T19:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with dax formula | Calculate an index with conditional over a period of 8 weeks</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-dax-formula-Calculate-an-index-with-conditional/m-p/3588200#M138498</link>
      <description>&lt;P&gt;Certainly, I can help you with that! It sounds like you want to create an index that is 0 if there has been zero volume for 8 consecutive weeks and 1 if there has been any volume greater than 0 within an 8-week period. Additionally, you want the result to be aggregated over the entire interval for each SAP and date.&lt;/P&gt;&lt;P&gt;You can achieve this using DAX (Data Analysis Expressions) in Power BI. Here's a general approach:&lt;/P&gt;&lt;P&gt;Assuming you have a table named YourTable with columns like SAP, Date, and Volume, you can create a calculated column for your index using the following DAX formula:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I8W =&lt;BR /&gt;VAR CurrentDate = YourTable[Date]&lt;BR /&gt;VAR EightWeeksAgo = CurrentDate - 56 // 8 weeks * 7 days per week = 56 days&lt;/P&gt;&lt;P&gt;RETURN&lt;BR /&gt;IF (&lt;BR /&gt;CALCULATE(&lt;BR /&gt;SUM(YourTable[Volume]),&lt;BR /&gt;FILTER(&lt;BR /&gt;YourTable,&lt;BR /&gt;YourTable[Date] &amp;gt;= EightWeeksAgo &amp;amp;&amp;amp;&lt;BR /&gt;YourTable[Date] &amp;lt;= CurrentDate &amp;amp;&amp;amp;&lt;BR /&gt;YourTable[Volume] &amp;gt; 0&lt;BR /&gt;)&lt;BR /&gt;) &amp;gt; 0,&lt;BR /&gt;1,&lt;BR /&gt;0&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This formula calculates the sum of the volume for the last 8 weeks, and if the sum is greater than 0, it returns 1; otherwise, it returns 0.&lt;/P&gt;&lt;P&gt;Remember to adjust column and table names according to your actual Power BI model.&lt;/P&gt;&lt;P&gt;To get the total sum filtered by each SAP and date, you can use this DAX measure:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TotalVolume = SUMX(FILTER(YourTable, YourTable[I8W] = 1), YourTable[Volume])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This measure calculates the sum of volumes for each SAP and date where the I8W index is 1.&lt;/P&gt;&lt;P&gt;Again, make sure to replace YourTable and column names with your actual table and column names.&lt;/P&gt;&lt;P&gt;These measures and calculated columns can be added to your Power BI report to achieve the desired results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;If this post&amp;nbsp;helps, then please consider&amp;nbsp;Accepting it as the solution&amp;nbsp;to help the other members find it more quickly.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In case there is still a problem, please feel free and explain your issue in detail,&amp;nbsp;It will be my pleasure to assist you in any way I can.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2023 06:52:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-dax-formula-Calculate-an-index-with-conditional/m-p/3588200#M138498</guid>
      <dc:creator>123abc</dc:creator>
      <dc:date>2023-12-18T06:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with dax formula | Calculate an index with conditional over a period of 8 weeks</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-dax-formula-Calculate-an-index-with-conditional/m-p/3599229#M139075</link>
      <description>&lt;P&gt;Unfortunately it didn't work, but I managed to solve it another way.&lt;/P&gt;&lt;P&gt;I ended up using DATESINPERIOD to do the calculation:&lt;/P&gt;&lt;P&gt;I8W = IF(&lt;BR /&gt;CALCULATE(&lt;BR /&gt;SUM('Table'[Net Sales Volume]),&lt;BR /&gt;DATESINPERIOD('Table'[Data], MAX('Table'[Data]),-56,DAY)) &amp;gt; 0&lt;BR /&gt;,1&lt;BR /&gt;,0&lt;BR /&gt;)&lt;/P&gt;</description>
      <pubDate>Fri, 22 Dec 2023 19:58:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-dax-formula-Calculate-an-index-with-conditional/m-p/3599229#M139075</guid>
      <dc:creator>carddosogabriel</dc:creator>
      <dc:date>2023-12-22T19:58:00Z</dc:date>
    </item>
  </channel>
</rss>

