<?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 How to calculate total 2 weeks from a calculated measure? in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-calculate-total-2-weeks-from-a-calculated-measure/m-p/1959930#M42840</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 tables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 1: Week, National SOM (National SOM is a calculated measure)&lt;/P&gt;&lt;P&gt;Table 2: Week, Sort&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to calculate total of every 2 weeks, for eg:&lt;/P&gt;&lt;P&gt;Jul21 W1 + Jul21 W2 = 4.5+4.6 = 9.1&lt;/P&gt;&lt;P&gt;Jun21 W4 + Jul21 W1 = 4.6+4.5=9.1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current calculation doesn't work for National SOM as a measure (col Total 2W in the first screenshot). I appreciate your help to advise me what I can do in this situation? Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Total 2W = 
CALCULATE (
    'Table 1'[National SOM],
FILTER (
ALL ( 'Table 2'),
'Table 2'[Sort] &amp;gt;= MAX ( 'Table 2'[Sort] ) -1
&amp;amp;&amp;amp; 'Table 2'[Sort] &amp;lt;= MAX ( 'Table 2'[Sort] )
)
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Jul 2021 13:00:18 GMT</pubDate>
    <dc:creator>milkynight</dc:creator>
    <dc:date>2021-07-15T13:00:18Z</dc:date>
    <item>
      <title>How to calculate total 2 weeks from a calculated measure?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-calculate-total-2-weeks-from-a-calculated-measure/m-p/1959930#M42840</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 tables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 1: Week, National SOM (National SOM is a calculated measure)&lt;/P&gt;&lt;P&gt;Table 2: Week, Sort&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to calculate total of every 2 weeks, for eg:&lt;/P&gt;&lt;P&gt;Jul21 W1 + Jul21 W2 = 4.5+4.6 = 9.1&lt;/P&gt;&lt;P&gt;Jun21 W4 + Jul21 W1 = 4.6+4.5=9.1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current calculation doesn't work for National SOM as a measure (col Total 2W in the first screenshot). I appreciate your help to advise me what I can do in this situation? Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Total 2W = 
CALCULATE (
    'Table 1'[National SOM],
FILTER (
ALL ( 'Table 2'),
'Table 2'[Sort] &amp;gt;= MAX ( 'Table 2'[Sort] ) -1
&amp;amp;&amp;amp; 'Table 2'[Sort] &amp;lt;= MAX ( 'Table 2'[Sort] )
)
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jul 2021 13:00:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-calculate-total-2-weeks-from-a-calculated-measure/m-p/1959930#M42840</guid>
      <dc:creator>milkynight</dc:creator>
      <dc:date>2021-07-15T13:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate total 2 weeks from a calculated measure?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-calculate-total-2-weeks-from-a-calculated-measure/m-p/1963564#M43015</link>
      <description>&lt;LI-CODE lang="csharp"&gt;// You must have proper relationships
// in place, e.g., the table with weeks
// must be connected to your fact in a
// one-to-many fashion.

[Total 2W] =
var MaxWeekVisible = MAX( Weeks[Sort] )
var Result = 
    CALCULATE(  
        // You must never precede a measure
        // with the name of the table it's
        // hosted in. On the other hand, columns
        // must always be preceded by the
        // table name.
        [National SOM],
        MaxWeekVisible - 1 &amp;lt;= Weeks[Sort],
        Weeks[Sort] &amp;lt;= MaxWeekVisible,
        ALL( Weeks )
    )
return
    Result
    
// If the above does not work, you have
// to show what your [National SOM] measure
// looks like because it seems to be flawed
// as it does not aggregates across many
// weeks, which stems from the measure's values
// you've shown. Please show the measure
// and the model. And please name your objects
// something that is meaningful. Also,
// it should not be 'Sort' but something like
// WeekID. In formulas do not calculate the
// same things many times over because this
// has the potential to slow down the code.
// If you have a value and need to use it in
// different places---see for example:
// MAX ( 'Table 2'[Sort] )---capture the value
// in a variable and use the variable from then
// on wards (variables are static, they don't
// change once they've been evaluated).
// Please read this guide and follow it:
// https://www.sqlbi.com/articles/rules-for-dax-code-formatting/&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 17 Jul 2021 14:05:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-calculate-total-2-weeks-from-a-calculated-measure/m-p/1963564#M43015</guid>
      <dc:creator>daxer-almighty</dc:creator>
      <dc:date>2021-07-17T14:05:10Z</dc:date>
    </item>
  </channel>
</rss>

