<?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 Average The Sum of Two Columns When Neither Are Blank Over 'x' Amount of Weeks in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-The-Sum-of-Two-Columns-When-Neither-Are-Blank-Over-x/m-p/4009267#M157543</link>
    <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been working on this problem for over a week and keep getting stuck.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Problem to Solve&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;- Divide the sum of SalesAmount by the sum of LeadQty for an AgentId in the last 4 Working Weeks. Essentially the four-week rolling average with some caveats.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Notes and Specifics&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;- I want to calculate only those dates (WeekEndDate) where both SalesAmount and LeadQty are not Blank.&lt;/P&gt;&lt;P&gt;- So a Working Week is a week where SalesAmount and/or LeadQty has a value&lt;/P&gt;&lt;P&gt;- One of the issues I'm running into is my measure counting a Non-Work Week as a Working Week.&lt;/P&gt;&lt;P&gt;- In the Sample Data below you'll see the calculation sums up the SalesAmount for each Working Week (highlighted) even if SalesAmount is Blank. This is because for that week LeadQty is not Blank. So we have 3 values for SalesAmount in those 4 Working Weeks. The same is true for Lead Qty, we are summing 3 values in the 4 Working Weeks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;DAX Measure&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;RollingAvg_4Week = 
VAR StartDate =
    FIRSTNONBLANK (
        'Calendar'[WeekEndDate],
        OR (
            SUM ( Sales[SalesAmount] ) &amp;gt; 0,
            SUM ( Leads[LeadQty] ) &amp;gt; 0
        )
    )
VAR EndDate =
    LASTNONBLANK (
        DATEADD ( 'Calendar'[WeekEndDate], -7, DAY ),
        OR (
            SUM ( Sales[SalesAmount] ) &amp;gt; 0,
            SUM ( Leads[LeadQty] ) &amp;gt; 0
        )
    )
RETURN
    CALCULATE (
        DIVIDE (
            SUM ( Sales[SalesAmount] ),
            SUM ( Leads[LeadQty] )
        ),
        DATESINPERIOD ( 'Calendar'[WeekEndDate], EndDate, -28, DAY )
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Sample Data in Excel&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;&lt;img /&gt;&lt;/STRONG&gt;&lt;/U&gt;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Power BI Model&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;- Agents Table w/ columns AgentId, Name&lt;/P&gt;&lt;P&gt;- Sales Table w/ columns AgentId, SalesAmount, SubmittedDate, WeekEndDate&lt;/P&gt;&lt;P&gt;- Lead Table w/ columns AgentId, LeadQty, WeekEndDate&lt;/P&gt;&lt;P&gt;- Calendar Table w/ columns Date, WeekEndDate&lt;/P&gt;&lt;P&gt;- Relationships: Calendar[Date] to Sales[SubmittedDate] and to Leads[WeekEndDate]&lt;/P&gt;&lt;P&gt;-- Agents[AgentId] to Sales[AgentId] and to Leads[AgentId]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all!&lt;/P&gt;</description>
    <pubDate>Tue, 25 Jun 2024 13:59:56 GMT</pubDate>
    <dc:creator>Jlindsey00</dc:creator>
    <dc:date>2024-06-25T13:59:56Z</dc:date>
    <item>
      <title>Average The Sum of Two Columns When Neither Are Blank Over 'x' Amount of Weeks</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-The-Sum-of-Two-Columns-When-Neither-Are-Blank-Over-x/m-p/4009267#M157543</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been working on this problem for over a week and keep getting stuck.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Problem to Solve&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;- Divide the sum of SalesAmount by the sum of LeadQty for an AgentId in the last 4 Working Weeks. Essentially the four-week rolling average with some caveats.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Notes and Specifics&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;- I want to calculate only those dates (WeekEndDate) where both SalesAmount and LeadQty are not Blank.&lt;/P&gt;&lt;P&gt;- So a Working Week is a week where SalesAmount and/or LeadQty has a value&lt;/P&gt;&lt;P&gt;- One of the issues I'm running into is my measure counting a Non-Work Week as a Working Week.&lt;/P&gt;&lt;P&gt;- In the Sample Data below you'll see the calculation sums up the SalesAmount for each Working Week (highlighted) even if SalesAmount is Blank. This is because for that week LeadQty is not Blank. So we have 3 values for SalesAmount in those 4 Working Weeks. The same is true for Lead Qty, we are summing 3 values in the 4 Working Weeks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;DAX Measure&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;RollingAvg_4Week = 
VAR StartDate =
    FIRSTNONBLANK (
        'Calendar'[WeekEndDate],
        OR (
            SUM ( Sales[SalesAmount] ) &amp;gt; 0,
            SUM ( Leads[LeadQty] ) &amp;gt; 0
        )
    )
VAR EndDate =
    LASTNONBLANK (
        DATEADD ( 'Calendar'[WeekEndDate], -7, DAY ),
        OR (
            SUM ( Sales[SalesAmount] ) &amp;gt; 0,
            SUM ( Leads[LeadQty] ) &amp;gt; 0
        )
    )
RETURN
    CALCULATE (
        DIVIDE (
            SUM ( Sales[SalesAmount] ),
            SUM ( Leads[LeadQty] )
        ),
        DATESINPERIOD ( 'Calendar'[WeekEndDate], EndDate, -28, DAY )
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Sample Data in Excel&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;&lt;img /&gt;&lt;/STRONG&gt;&lt;/U&gt;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Power BI Model&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;- Agents Table w/ columns AgentId, Name&lt;/P&gt;&lt;P&gt;- Sales Table w/ columns AgentId, SalesAmount, SubmittedDate, WeekEndDate&lt;/P&gt;&lt;P&gt;- Lead Table w/ columns AgentId, LeadQty, WeekEndDate&lt;/P&gt;&lt;P&gt;- Calendar Table w/ columns Date, WeekEndDate&lt;/P&gt;&lt;P&gt;- Relationships: Calendar[Date] to Sales[SubmittedDate] and to Leads[WeekEndDate]&lt;/P&gt;&lt;P&gt;-- Agents[AgentId] to Sales[AgentId] and to Leads[AgentId]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all!&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2024 13:59:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-The-Sum-of-Two-Columns-When-Neither-Are-Blank-Over-x/m-p/4009267#M157543</guid>
      <dc:creator>Jlindsey00</dc:creator>
      <dc:date>2024-06-25T13:59:56Z</dc:date>
    </item>
    <item>
      <title>Re: Average The Sum of Two Columns When Neither Are Blank Over 'x' Amount of Weeks</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-The-Sum-of-Two-Columns-When-Neither-Are-Blank-Over-x/m-p/4010090#M157770</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="562729" data-lia-user-login="Jlindsey00" class="lia-mention lia-mention-user"&gt;Jlindsey00&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a measure:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Measure = 
VAR CurrentDate = TODAY()
VAR StartDate = CurrentDate - 28
VAR EndDate = CurrentDate
VAR ValidSales = 
    CALCULATE(
        SUM('Table'[SaleAmount]),
        'Table'[SaleAmount] &amp;lt;&amp;gt; BLANK(),
        'Table'[LeadQty] &amp;lt;&amp;gt; BLANK(),
        FILTER(
            ALL('Date'),
            'Date'[Date] &amp;gt;= StartDate &amp;amp;&amp;amp; 'Date'[Date] &amp;lt;= EndDate
        )
    )
VAR ValidLeads = 
    CALCULATE(
        SUM('Table'[LeadQty]),
        'Table'[SaleAmount] &amp;lt;&amp;gt; BLANK(),
        'Table'[LeadQty] &amp;lt;&amp;gt; BLANK(),
        FILTER(
            ALL('Date'),
            'Date'[Date] &amp;gt;= StartDate &amp;amp;&amp;amp; 'Date'[Date] &amp;lt;= EndDate
        )
    )
RETURN
IF(ValidSales &amp;lt;&amp;gt; BLANK() &amp;amp;&amp;amp; ValidLeads &amp;lt;&amp;gt; BLANK(), ValidSales / ValidLeads, BLANK())&lt;/LI-CODE&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The final page visual effect is 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;If you have any other questions please feel free to contact me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The pbix file is attached.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Yang&lt;BR /&gt;Community Support Team&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is any post&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;to help the other members find it more quickly.&lt;BR /&gt;If I misunderstand your needs or you still have problems on it, please feel free to let us know.&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Thanks a lot!&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2024 01:49:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-The-Sum-of-Two-Columns-When-Neither-Are-Blank-Over-x/m-p/4010090#M157770</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-06-26T01:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: Average The Sum of Two Columns When Neither Are Blank Over 'x' Amount of Weeks</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-The-Sum-of-Two-Columns-When-Neither-Are-Blank-Over-x/m-p/4020192#M158595</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;, however this is not exactly what I was aiming for.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In you example, here is what should be added and averaged:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dates 6/20, 6/6, 5/30 and 5/16 as they are the first four dates with either a SalesAmount or LeadQty.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the sales amounts that should be summed are 1063 (6/20), 139 (5/30) and 437 (5/16).&lt;/P&gt;&lt;P&gt;And the lead quantities that should be summed are 18 (6/20), 20 (6/6) and 20 (5/30).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Given this information, how would you modify the 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;</description>
      <pubDate>Tue, 02 Jul 2024 09:52:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-The-Sum-of-Two-Columns-When-Neither-Are-Blank-Over-x/m-p/4020192#M158595</guid>
      <dc:creator>Jlindsey00</dc:creator>
      <dc:date>2024-07-02T09:52:10Z</dc:date>
    </item>
  </channel>
</rss>

