<?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: Calculating weekly running sum in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-weekly-running-sum/m-p/4270474#M169346</link>
    <description>&lt;P&gt;Hi Wilson,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have prepared a pbix file recreateing the Lakehouse and Semantic Model built in Fabric. I have uploaded the file to wetransfer: &lt;A href="https://we.tl/t-HcbGv4nD2m" target="_blank"&gt;https://we.tl/t-HcbGv4nD2m&lt;/A&gt;. Please let me know, if the link is expired.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
    <pubDate>Tue, 05 Nov 2024 10:17:01 GMT</pubDate>
    <dc:creator>mkaol</dc:creator>
    <dc:date>2024-11-05T10:17:01Z</dc:date>
    <item>
      <title>Calculating weekly running sum</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-weekly-running-sum/m-p/4246051#M168102</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;my semantic model has the following structure:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;In the fact table FACT_REVENUE, for each &lt;EM&gt;snapshot_date&lt;/EM&gt;/&lt;EM&gt;departure_date&lt;/EM&gt; combination there is a revenue value. It has full &lt;EM&gt;revenue&amp;nbsp;&lt;/EM&gt;value only for Sunday snapshot dates (&lt;EM&gt;sunday_delta&lt;/EM&gt; = 'sunday'). Snapshot dates for the rest of the week (&lt;EM&gt;sunday_delta&lt;/EM&gt; = 'delta') are deltas to the previous day. E.g., the revenue for Wednesday, is a sum of revenue for all &lt;EM&gt;snapshot_dates&lt;/EM&gt; since last Sunday to Wednesday (including Wednesday) for a certain&amp;nbsp;&lt;EM&gt;departure_date&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;Dimension tables DIM_SNAPSHOT_CALENDAR and DIM_DEPARTURE_CALENDAR contain all &lt;EM&gt;snapshot_dates&lt;/EM&gt; and all &lt;EM&gt;departure_dates&lt;/EM&gt;, accordingly.&lt;/P&gt;&lt;P&gt;I am using the following formula to calculate the weekly running sum of &lt;EM&gt;revenue&lt;/EM&gt;:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;revenue_running_sum = 
VAR maximus =
    MAX ( dim_snapshot_calendar[snapshot_date] )
VAR totalSplit =
    CALCULATE (
        SUM ( fact_revenue[revenue] ),
        dim_snapshot_calendar[snapshot_date] &amp;lt;= maximus,
        dim_snapshot_calendar[snapshot_date] &amp;gt;= maximus + 1 - WEEKDAY ( maximus - 7 )
    )
RETURN
    SUMX (
        ADDCOLUMNS (
            VALUES ( dim_snapshot_calendar[snapshot_date] ),
            "@Value", 0
        ),
        totalSplit
    )&lt;/LI-CODE&gt;&lt;P&gt;First maximum selected snapsh-date is obtained (maximums). The sum is calculated for &lt;EM&gt;snapshot_date&lt;/EM&gt;s &amp;lt;= maximus and &lt;EM&gt;snapshot_date&lt;/EM&gt;s &amp;gt;= last Sunday.&lt;/P&gt;&lt;P&gt;When filters on DIM_SNAPSHOT_CALENDAR[snapshot_date] and DIM_DEPARTURE_CALENDAR[&lt;EM&gt;departure_date&lt;/EM&gt;] are applied, the results are correct:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;However, if I split the result by FACT_REVENUE[&lt;EM&gt;days_before_departure&lt;/EM&gt;] (it is a difference between &lt;EM&gt;departure_date&lt;/EM&gt; and &lt;EM&gt;snapshot_date&lt;/EM&gt;), the results are split into each day since last Sunday:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;It seems to happen, because when calculating the running sum these &lt;EM&gt;snapshot_date&lt;/EM&gt;/&lt;EM&gt;departure_date&lt;/EM&gt; combinations are selected and when a filter from FACT_REVENUE table is in scope, then it is dispayed as split into those &lt;EM&gt;snapshot_date&lt;/EM&gt;/&lt;EM&gt;departure_date&lt;/EM&gt; combinations.&lt;/P&gt;&lt;P&gt;The expected result is:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Thus, the sum should be displayed for &lt;EM&gt;days_before_departure&lt;/EM&gt; = 1/31/2024 - 2/7/2024 = -7.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would appreciate any help or suggestions.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2024 07:15:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-weekly-running-sum/m-p/4246051#M168102</guid>
      <dc:creator>mkaol</dc:creator>
      <dc:date>2024-10-17T07:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating weekly running sum</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-weekly-running-sum/m-p/4249968#M168274</link>
      <description>&lt;P&gt;Hi mkaol,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The simplest solution is to make sure your date table also has a week number column. Standard DAX is notoriously cumbersome with a lot of time intelligence functionality that becomes a lot simpler once you incorporate more columns into your date table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check out &lt;A href="https://www.linkedin.com/posts/brianjuliusdc_powerbi-offsets-dax-activity-7149485195954454528-sWk4" target="_self"&gt;Brian Julius' awesome LinkedIn post&lt;/A&gt; for more details.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And of course, if you still need more help, please feel free to let me know where you're stuck and I'd be more than happy to assist. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;----------------------------------&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;P.S. Need a more in-depth consultation for your Power BI data modeling or DAX issues? Feel free to hire me on &lt;A href="https://www.upwork.com/freelancers/~01bc08c63d83566d45" target="_blank"&gt;Upwork&lt;/A&gt; or DM me directly on here! I would love to clear up your Power BI headaches.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2024 03:46:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-weekly-running-sum/m-p/4249968#M168274</guid>
      <dc:creator>Wilson_</dc:creator>
      <dc:date>2024-10-21T03:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating weekly running sum</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-weekly-running-sum/m-p/4252645#M168426</link>
      <description>&lt;P&gt;Hi Wilson,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your response.&lt;/P&gt;&lt;P&gt;Adding week number to the table seems like a good idea. However, unfortunately, I could achieve correct result using this approach. I have tried to:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;filter SNAP_DT &amp;lt;= MAX(dim_snapshot_calendar[SNAP_DT])&lt;/LI&gt;&lt;LI&gt;calculate sum aggregated by snap week number&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;For every selected snap_dt.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I have tried some approaches, for example:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fact_revenue[NN YQ CY v2 snap_week] = 
VAR maximus = MAX ( dim_snapshot_calendar[SNAP_DT] ) 
VAR totalSplit = CALCULATE ( SUM ( fact_revenue[revenue] ), 
dim_snapshot_calendar[SNAP_DT] &amp;lt;= maximus ) 

return 
SUMX( 
SUMMARIZE ( fact_revenue_v2, 
dim_snapshot_calendar[SNAP_WEEK_NUM] ) 
,totalSplit) &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It returns only the value for the selected SNAP_DT and not the sum of all SNAP_DTs within the same SNAP_WEEK_NUM, where SNAP_DT &amp;lt;= selected SNAP_DT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I were to achieve simillar results using SQL, it would be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SELECT fact_revenue[snap_week_num], SUM(fact_revenue[revenue]) 
FROM fact_revenue 
WHERE fact_revenue[snapshot_date] &amp;gt; '2024-02-07' 
GROUP BY fact_revenue[snap_week_num] 
; &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you maybe tell me, how to build an analogous DAX measure?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2024 13:21:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-weekly-running-sum/m-p/4252645#M168426</guid>
      <dc:creator>mkaol</dc:creator>
      <dc:date>2024-10-22T13:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating weekly running sum</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-weekly-running-sum/m-p/4259612#M168799</link>
      <description>&lt;P&gt;mkaol,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please share a sample pbix file? (If you don't know how, please check the pinned thread in the forum.) It would make debugging your issue easier. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Oct 2024 23:15:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-weekly-running-sum/m-p/4259612#M168799</guid>
      <dc:creator>Wilson_</dc:creator>
      <dc:date>2024-10-27T23:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating weekly running sum</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-weekly-running-sum/m-p/4270474#M169346</link>
      <description>&lt;P&gt;Hi Wilson,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have prepared a pbix file recreateing the Lakehouse and Semantic Model built in Fabric. I have uploaded the file to wetransfer: &lt;A href="https://we.tl/t-HcbGv4nD2m" target="_blank"&gt;https://we.tl/t-HcbGv4nD2m&lt;/A&gt;. Please let me know, if the link is expired.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2024 10:17:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-weekly-running-sum/m-p/4270474#M169346</guid>
      <dc:creator>mkaol</dc:creator>
      <dc:date>2024-11-05T10:17:01Z</dc:date>
    </item>
  </channel>
</rss>

