<?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 the Monthly Total at a Specific Point in Time in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Monthly-Total-at-a-Specific-Point-in-Time/m-p/4377117#M173787</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="614480" data-lia-user-login="TJK" class="lia-mention lia-mention-user"&gt;TJK&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;please try this code&lt;BR /&gt;&lt;BR /&gt;Monthly Total Loan Amount =&lt;BR /&gt;VAR SelectedDate = MAX('Date'[Date]) -- The selected date from the slicer&lt;BR /&gt;VAR LatestRecords =&lt;BR /&gt;SUMMARIZE(&lt;BR /&gt;FILTER(&lt;BR /&gt;'Opportunity History',&lt;BR /&gt;'Opportunity History'[CreatedDate] &amp;lt;= SelectedDate&lt;BR /&gt;),&lt;BR /&gt;'Opportunity History'[OpportunityId],&lt;BR /&gt;"LatestCreatedDate",&lt;BR /&gt;MAX('Opportunity History'[CreatedDate])&lt;BR /&gt;)&lt;BR /&gt;VAR FilteredOpportunities =&lt;BR /&gt;FILTER(&lt;BR /&gt;ADDCOLUMNS(&lt;BR /&gt;LatestRecords,&lt;BR /&gt;"CloseDate",&lt;BR /&gt;CALCULATE(&lt;BR /&gt;MAX('Opportunity History'[CloseDate]),&lt;BR /&gt;'Opportunity History'[CreatedDate] = [LatestCreatedDate]&lt;BR /&gt;),&lt;BR /&gt;"LoanAmount",&lt;BR /&gt;CALCULATE(&lt;BR /&gt;MAX('Opportunity History'[Loan Amount]),&lt;BR /&gt;'Opportunity History'[CreatedDate] = [LatestCreatedDate]&lt;BR /&gt;)&lt;BR /&gt;),&lt;BR /&gt;[CloseDate] &amp;lt;= EOMONTH(SelectedDate, 0) -- Include only CloseDates in the selected month&lt;BR /&gt;)&lt;BR /&gt;RETURN&lt;BR /&gt;SUMX(FilteredOpportunities, [LoanAmount])&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Govind Sapkade ( Data Analyst , Power BI PL 300 Certified , MS Fabric Enthusiast )&lt;BR /&gt;Linkdin :&amp;nbsp;&lt;A href="http://www.linkedin.com/in/govind-sapkade-845104225" target="_blank"&gt;www.linkedin.com/in/govind-sapkade-845104225&lt;/A&gt;&lt;BR /&gt;Youtube :&amp;nbsp;&lt;A href="http://www.youtube.com/@govind_dataanalyst" target="_blank"&gt;http://www.youtube.com/@govind_dataanalyst&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jan 2025 07:03:44 GMT</pubDate>
    <dc:creator>govind_021</dc:creator>
    <dc:date>2025-01-23T07:03:44Z</dc:date>
    <item>
      <title>Calculating the Monthly Total at a Specific Point in Time</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Monthly-Total-at-a-Specific-Point-in-Time/m-p/4376475#M173763</link>
      <description>&lt;P&gt;I'm struggling to solve this tricky "point in time" calculation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 4 columns in the 'Opportunity History' table.&lt;BR /&gt;1. OpportunityId&lt;BR /&gt;2. CreatedDate&lt;BR /&gt;3. CloseDate&lt;BR /&gt;4. Loan Amount&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also have a 'Date' table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each OpportunityId has multiple records, meaning the OpportunityId is not a unique identifier. Each time the CloseDate changes, a new record is created. The CreatedDate column tracks the date of change of the CloseDate, and the CloseDate column tracks the date of each new close date. The Loan Amount column has the same value for all records for each OpportunityId.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a measure that equals the total loan amount (sum) that is closing in the given month at a specific point in time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, if I select 12/1/2024 in my slicer, I want the output to be the sum of Loan Amount of all OpportunityIds with a CloseDate equal to or before 12/31/2024 at that point in time. I want to make sure it includes all OpportunityIds with their most recent CreatedDates being before 12/1/2024, even if the most recent CreatedDate was 11/1/2024 with a CloseDate of 12/31/2024.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, if on 12/2/2024 the CloseDate changed to 1/1/2025, then I would not expect the output to include the sum of this OpportunityId when 12/2/2024 is selected in the slicer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If on 12/3/2024 the CloseDate changes back to 12/31/2024, then I would expect the output to include the sum of this OpportunityId when 12/3/2024 is selected in the slicer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm also not sure if the relationship between my two tables should use CreatedDate or CloseDate.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All help is greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 21:10:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Monthly-Total-at-a-Specific-Point-in-Time/m-p/4376475#M173763</guid>
      <dc:creator>TJK</dc:creator>
      <dc:date>2025-01-22T21:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating the Monthly Total at a Specific Point in Time</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Monthly-Total-at-a-Specific-Point-in-Time/m-p/4377046#M173784</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="614480" data-lia-user-login="TJK" class="lia-mention lia-mention-user"&gt;TJK&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To calculate the total loan amount for OpportunityIds closing at a specific point in time, create a DAX measure that sums the &lt;STRONG&gt;Loan Amount&lt;/STRONG&gt; for records with a &lt;STRONG&gt;CloseDate&lt;/STRONG&gt; &amp;lt;= the selected slicer date and where the &lt;STRONG&gt;CreatedDate&lt;/STRONG&gt; is also before or on the selected date. The measure should filter the data to only include the most recent record for each &lt;STRONG&gt;OpportunityId&lt;/STRONG&gt; based on the latest &lt;STRONG&gt;CloseDate&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;You should use the &lt;STRONG&gt;CloseDate&lt;/STRONG&gt; for the relationship with the &lt;STRONG&gt;Date&lt;/STRONG&gt; table. The measure will dynamically adjust based on the slicer date and consider only the latest &lt;STRONG&gt;CloseDate&lt;/STRONG&gt; before the selected date, ensuring that only valid loan amounts are included.&lt;/P&gt;
&lt;P&gt;Test the measure with various slicer dates to ensure it behaves as expected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Loan Amount at Point in Time = 
CALCULATE(
    SUM('Opportunity History'[Loan Amount]), 
    FILTER(
        'Opportunity History', 
        'Opportunity History'[CloseDate] &amp;lt;= MAX('Date'[Date]) &amp;amp;&amp;amp; 
        'Opportunity History'[CreatedDate] &amp;lt;= MAX('Date'[Date]) &amp;amp;&amp;amp;
        'Opportunity History'[OpportunityId] IN 
            CALCULATETABLE(
                VALUES('Opportunity History'[OpportunityId]), 
                FILTER(
                    'Opportunity History', 
                    'Opportunity History'[CloseDate] &amp;lt;= MAX('Date'[Date])
                )
            )
    )
)
&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 23 Jan 2025 06:29:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Monthly-Total-at-a-Specific-Point-in-Time/m-p/4377046#M173784</guid>
      <dc:creator>Poojara_D12</dc:creator>
      <dc:date>2025-01-23T06:29:47Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating the Monthly Total at a Specific Point in Time</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Monthly-Total-at-a-Specific-Point-in-Time/m-p/4377117#M173787</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="614480" data-lia-user-login="TJK" class="lia-mention lia-mention-user"&gt;TJK&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;please try this code&lt;BR /&gt;&lt;BR /&gt;Monthly Total Loan Amount =&lt;BR /&gt;VAR SelectedDate = MAX('Date'[Date]) -- The selected date from the slicer&lt;BR /&gt;VAR LatestRecords =&lt;BR /&gt;SUMMARIZE(&lt;BR /&gt;FILTER(&lt;BR /&gt;'Opportunity History',&lt;BR /&gt;'Opportunity History'[CreatedDate] &amp;lt;= SelectedDate&lt;BR /&gt;),&lt;BR /&gt;'Opportunity History'[OpportunityId],&lt;BR /&gt;"LatestCreatedDate",&lt;BR /&gt;MAX('Opportunity History'[CreatedDate])&lt;BR /&gt;)&lt;BR /&gt;VAR FilteredOpportunities =&lt;BR /&gt;FILTER(&lt;BR /&gt;ADDCOLUMNS(&lt;BR /&gt;LatestRecords,&lt;BR /&gt;"CloseDate",&lt;BR /&gt;CALCULATE(&lt;BR /&gt;MAX('Opportunity History'[CloseDate]),&lt;BR /&gt;'Opportunity History'[CreatedDate] = [LatestCreatedDate]&lt;BR /&gt;),&lt;BR /&gt;"LoanAmount",&lt;BR /&gt;CALCULATE(&lt;BR /&gt;MAX('Opportunity History'[Loan Amount]),&lt;BR /&gt;'Opportunity History'[CreatedDate] = [LatestCreatedDate]&lt;BR /&gt;)&lt;BR /&gt;),&lt;BR /&gt;[CloseDate] &amp;lt;= EOMONTH(SelectedDate, 0) -- Include only CloseDates in the selected month&lt;BR /&gt;)&lt;BR /&gt;RETURN&lt;BR /&gt;SUMX(FilteredOpportunities, [LoanAmount])&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Govind Sapkade ( Data Analyst , Power BI PL 300 Certified , MS Fabric Enthusiast )&lt;BR /&gt;Linkdin :&amp;nbsp;&lt;A href="http://www.linkedin.com/in/govind-sapkade-845104225" target="_blank"&gt;www.linkedin.com/in/govind-sapkade-845104225&lt;/A&gt;&lt;BR /&gt;Youtube :&amp;nbsp;&lt;A href="http://www.youtube.com/@govind_dataanalyst" target="_blank"&gt;http://www.youtube.com/@govind_dataanalyst&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2025 07:03:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Monthly-Total-at-a-Specific-Point-in-Time/m-p/4377117#M173787</guid>
      <dc:creator>govind_021</dc:creator>
      <dc:date>2025-01-23T07:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating the Monthly Total at a Specific Point in Time</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Monthly-Total-at-a-Specific-Point-in-Time/m-p/4377971#M173814</link>
      <description>&lt;P&gt;I am getting "Column 'LatestCreatedDate' cannot be found or may not be used in this expression."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also what is the relationship between the date table and Opportunity History table?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2025 14:47:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Monthly-Total-at-a-Specific-Point-in-Time/m-p/4377971#M173814</guid>
      <dc:creator>TJK</dc:creator>
      <dc:date>2025-01-23T14:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating the Monthly Total at a Specific Point in Time</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Monthly-Total-at-a-Specific-Point-in-Time/m-p/4377976#M173815</link>
      <description>&lt;P&gt;I also tried using ChatGPT too. This code does not give an accurate output.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2025 14:49:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Monthly-Total-at-a-Specific-Point-in-Time/m-p/4377976#M173815</guid>
      <dc:creator>TJK</dc:creator>
      <dc:date>2025-01-23T14:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating the Monthly Total at a Specific Point in Time</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Monthly-Total-at-a-Specific-Point-in-Time/m-p/4379465#M173851</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="614480" data-lia-user-login="TJK" class="lia-mention lia-mention-user"&gt;TJK&lt;/a&gt;, hello&amp;nbsp;govind_021&amp;nbsp; and&amp;nbsp;Poojara_D12&amp;nbsp;, thank you for your prompt reply!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on my understanding, I have outlined the logic below. If this is not feasible for you, please let me know!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;CloseDate Range:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The CloseDate must fall within the same month as the selected date (i.e., it should be on or after the first day of the month and on or before the last day of the month).&lt;/LI&gt;
&lt;LI&gt;The CloseDate must be later than the selected date.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;CreatedDate Range:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;For each OpportunityId, only records with the maximum CreatedDate that is less than or equal to the selected date are considered.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try the following measure:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Measure 2 = 
VAR SelectedDate = SELECTEDVALUE('Date'[Date])  
VAR StartOfMon = DATE(YEAR(SelectedDate), MONTH(SelectedDate), 1) 
VAR EndOfMonthDate = EOMONTH(SelectedDate, 0)  

RETURN
CALCULATE(
    SUM('Opportunity History'[Loan Amount]),  
    FILTER(
        'Opportunity History',
        'Opportunity History'[CloseDate] &amp;gt;= StartOfMon &amp;amp;&amp;amp;  
        'Opportunity History'[CloseDate] &amp;lt;= EndOfMonthDate &amp;amp;&amp;amp;  
        'Opportunity History'[CloseDate] &amp;gt;= SelectedDate   
    ),
    FILTER(
        'Opportunity History',
        'Opportunity History'[CreatedDate] = 
        CALCULATE(
            MAX('Opportunity History'[CreatedDate]),  
            ALLEXCEPT('Opportunity History', 'Opportunity History'[OpportunityId]),  
            'Opportunity History'[CreatedDate] &amp;lt;= SelectedDate  
        )
    )
)
&lt;/LI-CODE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Joyce&lt;/P&gt;
&lt;P&gt;If this post&amp;nbsp;&lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;Accept it as the solution&lt;/STRONG&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2025 09:29:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Monthly-Total-at-a-Specific-Point-in-Time/m-p/4379465#M173851</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2025-01-24T09:29:42Z</dc:date>
    </item>
  </channel>
</rss>

