<?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: Advanced Sum between Dates in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Advanced-Sum-between-Dates/m-p/2551841#M72235</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="296219" data-lia-user-login="Contezini" class="lia-mention lia-mention-user"&gt;Contezini&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a sample file with the solution&amp;nbsp;&lt;A href="https://www.dropbox.com/t/BFyYg068Dfa9YNbe" target="_blank"&gt;https://www.dropbox.com/t/BFyYg068Dfa9YNbe&lt;/A&gt;&lt;BR /&gt;We have two issue to solve here.&lt;/P&gt;&lt;P&gt;The first one we have define which start belongs to which end as there is no stage or ranking column that related each start to its relevant&amp;nbsp;end.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The 2nd issue is generate only the relevant&amp;nbsp;rows in between each start and stop.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the data model with inactive or no relationship with the date table.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;The first issue can be solved by creating the following calculated column&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Ranking = 
RANKX ( 
    CALCULATETABLE ( 
        'Site Log', 
        ALLEXCEPT ( 'Site Log', 'Site Log'[Site_ID],'Site Log'[Log Change] ) 
    ), 
    'Site Log'[Date],, 
    ASC 
)&lt;/LI-CODE&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;The measure that generates the relevant rows with the relevant site size&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Filter Measure = 
VAR CurrentDate = MAX ( 'Date'[Date] )
VAR T1 =
    ADDCOLUMNS (
        SUMMARIZE ( 'Site Log', 'Site Log'[Site_ID],'Site Log'[Ranking],'Site Sizes'[Site_Size] ),
        "@Start", CALCULATE ( MAX ( 'Site Log'[Date] ), 'Site Log'[Log Change] = "Started" ),
        "@End", COALESCE ( CALCULATE ( MAX ( 'Site Log'[Date] ), 'Site Log'[Log Change] = "Ended" ), TODAY ( ) )
    )
VAR T2 =
    GENERATE ( 
        T1,
        VAR StartDate = [@Start]
        VAR EndDate =  [@End]
        RETURN
            CALENDAR ( StartDate, EndDate )
    )
VAR T3 = FILTER ( T2, [@Start] &amp;lt;= CurrentDate &amp;amp;&amp;amp; [@End] &amp;gt;= CurrentDate )
RETURN
    MAXX ( T3, [Site_Size] )&lt;/LI-CODE&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Jun 2022 05:13:43 GMT</pubDate>
    <dc:creator>tamerj1</dc:creator>
    <dc:date>2022-06-01T05:13:43Z</dc:date>
    <item>
      <title>Advanced Sum between Dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Advanced-Sum-between-Dates/m-p/2549543#M72096</link>
      <description>&lt;P&gt;Dear community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know there are hundreds of topics regarding calculation of Sum Between dates, but none of them seems to fit my needs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 data tables + 1 calendar table&lt;/P&gt;&lt;P&gt;Site Sizes:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Site_ID&lt;/TD&gt;&lt;TD&gt;Site_Size&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;S_001&lt;/TD&gt;&lt;TD&gt;67&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;S_002&lt;/TD&gt;&lt;TD&gt;33&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;S_003&lt;/TD&gt;&lt;TD&gt;47&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;S_004&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and Site Log registration:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Site_ID&lt;/TD&gt;&lt;TD&gt;Log Change&lt;/TD&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;S_001&lt;/TD&gt;&lt;TD&gt;Started&lt;/TD&gt;&lt;TD&gt;01/01/2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;S_001&lt;/TD&gt;&lt;TD&gt;Ended&lt;/TD&gt;&lt;TD&gt;28/02/2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;S_001&lt;/TD&gt;&lt;TD&gt;Started&lt;/TD&gt;&lt;TD&gt;16/05/2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;S_002&lt;/TD&gt;&lt;TD&gt;Started&lt;/TD&gt;&lt;TD&gt;01/02/2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;S_002&lt;/TD&gt;&lt;TD&gt;Ended&lt;/TD&gt;&lt;TD&gt;07/03/2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;S_002&lt;/TD&gt;&lt;TD&gt;Started&lt;/TD&gt;&lt;TD&gt;01/05/2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;S_002&lt;/TD&gt;&lt;TD&gt;Ended&lt;/TD&gt;&lt;TD&gt;31/05/2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;S_003&lt;/TD&gt;&lt;TD&gt;Started&lt;/TD&gt;&lt;TD&gt;01/01/2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;S_003&lt;/TD&gt;&lt;TD&gt;Ended&lt;/TD&gt;&lt;TD&gt;10/03/2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;S_004&lt;/TD&gt;&lt;TD&gt;Started&lt;/TD&gt;&lt;TD&gt;01/01/2022&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With this data, I want to dinamically know the Total Active Size per Date.&lt;/P&gt;&lt;P&gt;The result should be a measure that allows me creating visualizations such as follows:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my real dataset, I have ~2000 Site Ids, some of them with +10 Log changes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe there should be an easy, but maybe non-intuitive solution...&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 08:14:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Advanced-Sum-between-Dates/m-p/2549543#M72096</guid>
      <dc:creator>Contezini</dc:creator>
      <dc:date>2022-05-31T08:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced Sum between Dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Advanced-Sum-between-Dates/m-p/2551690#M72223</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="296219" data-lia-user-login="Contezini" class="lia-mention lia-mention-user"&gt;Contezini&lt;/a&gt; , merge size and log tables &lt;/P&gt;
&lt;P&gt;or create a measure&lt;/P&gt;
&lt;P&gt;M1 = sumx(relatedtable(Size), Size(Size)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then try a measure like &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;calculate( [M1], filter(all(Date), Date[Date] &amp;lt;= Max(Date[Date])), filter(Log, Log[Log Change] ="Started")) &lt;BR /&gt;- calculate( [M1], filter(all(Date), Date[Date] &amp;lt;= Max(Date[Date])), filter(Log, Log[Log Change] ="Ended"))&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2022 02:46:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Advanced-Sum-between-Dates/m-p/2551690#M72223</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2022-06-01T02:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced Sum between Dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Advanced-Sum-between-Dates/m-p/2551841#M72235</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="296219" data-lia-user-login="Contezini" class="lia-mention lia-mention-user"&gt;Contezini&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a sample file with the solution&amp;nbsp;&lt;A href="https://www.dropbox.com/t/BFyYg068Dfa9YNbe" target="_blank"&gt;https://www.dropbox.com/t/BFyYg068Dfa9YNbe&lt;/A&gt;&lt;BR /&gt;We have two issue to solve here.&lt;/P&gt;&lt;P&gt;The first one we have define which start belongs to which end as there is no stage or ranking column that related each start to its relevant&amp;nbsp;end.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The 2nd issue is generate only the relevant&amp;nbsp;rows in between each start and stop.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the data model with inactive or no relationship with the date table.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;The first issue can be solved by creating the following calculated column&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Ranking = 
RANKX ( 
    CALCULATETABLE ( 
        'Site Log', 
        ALLEXCEPT ( 'Site Log', 'Site Log'[Site_ID],'Site Log'[Log Change] ) 
    ), 
    'Site Log'[Date],, 
    ASC 
)&lt;/LI-CODE&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;The measure that generates the relevant rows with the relevant site size&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Filter Measure = 
VAR CurrentDate = MAX ( 'Date'[Date] )
VAR T1 =
    ADDCOLUMNS (
        SUMMARIZE ( 'Site Log', 'Site Log'[Site_ID],'Site Log'[Ranking],'Site Sizes'[Site_Size] ),
        "@Start", CALCULATE ( MAX ( 'Site Log'[Date] ), 'Site Log'[Log Change] = "Started" ),
        "@End", COALESCE ( CALCULATE ( MAX ( 'Site Log'[Date] ), 'Site Log'[Log Change] = "Ended" ), TODAY ( ) )
    )
VAR T2 =
    GENERATE ( 
        T1,
        VAR StartDate = [@Start]
        VAR EndDate =  [@End]
        RETURN
            CALENDAR ( StartDate, EndDate )
    )
VAR T3 = FILTER ( T2, [@Start] &amp;lt;= CurrentDate &amp;amp;&amp;amp; [@End] &amp;gt;= CurrentDate )
RETURN
    MAXX ( T3, [Site_Size] )&lt;/LI-CODE&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2022 05:13:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Advanced-Sum-between-Dates/m-p/2551841#M72235</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-06-01T05:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced Sum between Dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Advanced-Sum-between-Dates/m-p/2563115#M72972</link>
      <description>&lt;P&gt;Hi Tamerj1,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you for your detailed solution! I have read it and tried out from the moment you posted.&lt;/P&gt;&lt;P&gt;The solution worked for small amount of data, but has a clear performance issue.&lt;/P&gt;&lt;P&gt;My real datatable has too many data for this measure so that it takes too long to load (after 5min waiting for the visualization to load, I gave up waiting).&lt;/P&gt;&lt;P&gt;I saw a very big performance issue when using this only as measure, and considered setting T2 as a calculated Table. I believe this should enhance the performance. Though I need the data to be dynamic (i.e., update when other filters are set) and I'm not sure if my solution will work....&lt;/P&gt;&lt;P&gt;Since I still haven't had time to finish this adaptations and check the results, I didn't accept your answer as solution yet (I think it was automatically set as solution). But I except to be able to check it in the coming days!&lt;/P&gt;&lt;P&gt;For now, thanks for your engagement! I am looking forward to get back to this soon&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 07:43:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Advanced-Sum-between-Dates/m-p/2563115#M72972</guid>
      <dc:creator>Contezini</dc:creator>
      <dc:date>2022-06-07T07:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced Sum between Dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Advanced-Sum-between-Dates/m-p/2563358#M72983</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="296219" data-lia-user-login="Contezini" class="lia-mention lia-mention-user"&gt;Contezini&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;The issue is that the visual will consume a huge amount of time to load such huge number of sites. But even when it completes loading the chart will not be readable at all! You need in all cases to provide some kind of filter to limit the number of sites involved in one chart. The calculated table will be faster for sure but wil still be relatively slow if too many sites are involved. Also it cannot be dynamic.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 08:51:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Advanced-Sum-between-Dates/m-p/2563358#M72983</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-06-07T08:51:38Z</dc:date>
    </item>
  </channel>
</rss>

