<?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: Looking for DAX to handle Payments Applied to Invoices and Calculate Outstanding Amount in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-DAX-to-handle-Payments-Applied-to-Invoices-and/m-p/3143008#M112292</link>
    <description>&lt;P&gt;Try These...&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Invoice Amount =  SUMX(SUMMARIZE(Table,Table[Invoice],"Invoice Total",MAX(Table[Inv. Amt.])),[Invoice Total])

Applied Amount = SUM(Table[Applied Amount])

OutStanding Amount = SUMX(SUMMARIZE(Table,Table[Invoice],Table[Invoice Date],"InvoiceAmount",[Invoice Amount],"InvoicePayment",[Applied Amount]),[InvoiceAmount]-[InvoicePayment])&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 20 Mar 2023 17:14:39 GMT</pubDate>
    <dc:creator>BrianConnelly</dc:creator>
    <dc:date>2023-03-20T17:14:39Z</dc:date>
    <item>
      <title>Looking for DAX to handle Payments Applied to Invoices and Calculate Outstanding Amount</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-DAX-to-handle-Payments-Applied-to-Invoices-and/m-p/3142992#M112291</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Goal: Create DAX Measures to accuratley calculate Outstanding Amt., accurate invoice totals, and potentailly other KPIs.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;STRONG&gt;All of the columns in the visual below are in a &lt;STRONG&gt;single table in the PowerBI Data Model.&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;UL&gt;&lt;LI&gt;There is no separate "Date" table involved currently.&lt;/LI&gt;&lt;LI&gt;There are no separate tables for invoice header and payment detail currently.&lt;UL&gt;&lt;LI&gt;If no payments have been made, there is just a single row for the invoice with &lt;EM&gt;Applied Amt.&amp;nbsp;&lt;/EM&gt;blank&lt;EM&gt;.&lt;/EM&gt;&lt;/LI&gt;&lt;LI&gt;If the invoice was paid in full with one payment, there will be just a single row for the invoice.&lt;/LI&gt;&lt;LI&gt;If the invoice was paid with multiple payments, there will be multiple rows for each invoice&lt;BR /&gt;(&lt;STRONG&gt;as in the screenshot below)&lt;/STRONG&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/LI&gt;&lt;LI&gt;The only DAX calculation currenlty is "Outstanding Amount".&lt;DIV&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;Outstanding Amt. = &lt;/SPAN&gt;&lt;SPAN&gt;sum&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Invoices and Payments'&lt;/SPAN&gt;&lt;SPAN&gt;[Inv. Amt.]&lt;/SPAN&gt;&lt;SPAN&gt;)+ &lt;/SPAN&gt;&lt;SPAN&gt;sum&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Invoices and Payments'&lt;/SPAN&gt;&lt;SPAN&gt;[Applied Amt.]&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;To make this work properly, the DAX should look for any previously &lt;EM&gt;Applied Amt.&lt;/EM&gt; and &lt;EM&gt;Outstanding Amt.&lt;/EM&gt; should be the remaining unpaid balance.&lt;/STRONG&gt; So below has 2 issues:&lt;BR /&gt;&lt;BR /&gt;&lt;OL&gt;&lt;LI&gt;&lt;EM&gt;Outstanding Amt.&lt;/EM&gt; is correct for the 06/13 &lt;EM&gt;Applied Dt.&lt;/EM&gt; record,&lt;BR /&gt;but should be 0 after the 06/16 payment is applied.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;&lt;LI&gt;The total &lt;EM&gt;Outstanding Amt.&lt;/EM&gt; should be 0 for this &lt;EM&gt;Inv No.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;/EM&gt;The total Inv. Amt. here should be $70,387.30 not $140,774.60.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;Can I do what I'm trying to do here with DAX, or do I need to structure the data differenlty in PowerQuery before attempting to do this type of calculation?&lt;/STRONG&gt;&lt;EM&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2023 17:05:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-DAX-to-handle-Payments-Applied-to-Invoices-and/m-p/3142992#M112291</guid>
      <dc:creator>Karl-D</dc:creator>
      <dc:date>2023-03-20T17:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for DAX to handle Payments Applied to Invoices and Calculate Outstanding Amount</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-DAX-to-handle-Payments-Applied-to-Invoices-and/m-p/3143008#M112292</link>
      <description>&lt;P&gt;Try These...&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Invoice Amount =  SUMX(SUMMARIZE(Table,Table[Invoice],"Invoice Total",MAX(Table[Inv. Amt.])),[Invoice Total])

Applied Amount = SUM(Table[Applied Amount])

OutStanding Amount = SUMX(SUMMARIZE(Table,Table[Invoice],Table[Invoice Date],"InvoiceAmount",[Invoice Amount],"InvoicePayment",[Applied Amount]),[InvoiceAmount]-[InvoicePayment])&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 20 Mar 2023 17:14:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-DAX-to-handle-Payments-Applied-to-Invoices-and/m-p/3143008#M112292</guid>
      <dc:creator>BrianConnelly</dc:creator>
      <dc:date>2023-03-20T17:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for DAX to handle Payments Applied to Invoices and Calculate Outstanding Amount</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-DAX-to-handle-Payments-Applied-to-Invoices-and/m-p/3143093#M112298</link>
      <description>&lt;P&gt;Thanks Brian.&amp;nbsp; That got my totals right, but how can I make the yellow number = 0?&lt;BR /&gt;&lt;BR /&gt;In other words, the first payment on 6/13 brought my outstanding amt. down to $47,388.73, so after applying the second payment on 6/16, the outstanding should be 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2023 18:05:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-DAX-to-handle-Payments-Applied-to-Invoices-and/m-p/3143093#M112298</guid>
      <dc:creator>Karl-D</dc:creator>
      <dc:date>2023-03-20T18:05:40Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for DAX to handle Payments Applied to Invoices and Calculate Outstanding Amount</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-DAX-to-handle-Payments-Applied-to-Invoices-and/m-p/3143165#M112304</link>
      <description>&lt;P&gt;Try it this way...&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Invoice Amount =  SUMX(SUMMARIZE(Table,Table[Invoice],"Invoice Total",MAX(Table[Inv. Amt.])),[Invoice Total])

Applied Amount = SUM(Table[Applied Amount])

variableTable = SUMMARIZE(Table,Table[Invoice],Table[Invoice Date],"InvoiceAmount",[Invoice Amount],"InvoicePayment",[Applied Amount])

OutStanding Amount = SUMX(FILTER(ALLSELECTED(variableTable),Table[Invoice Date]&amp;lt;=MAX(Table[Invoice Date])),[InvoiceAmount]-[InvoicePayment])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2023 18:45:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-DAX-to-handle-Payments-Applied-to-Invoices-and/m-p/3143165#M112304</guid>
      <dc:creator>BrianConnelly</dc:creator>
      <dc:date>2023-03-20T18:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for DAX to handle Payments Applied to Invoices and Calculate Outstanding Amount</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-DAX-to-handle-Payments-Applied-to-Invoices-and/m-p/3143201#M112313</link>
      <description>&lt;P&gt;Cool, I see where you're going there with the variableTable, and I got that created successfully.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, it looks like we're missing something in the final step now?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2023 19:12:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-DAX-to-handle-Payments-Applied-to-Invoices-and/m-p/3143201#M112313</guid>
      <dc:creator>Karl-D</dc:creator>
      <dc:date>2023-03-20T19:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for DAX to handle Payments Applied to Invoices and Calculate Outstanding Amount</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-DAX-to-handle-Payments-Applied-to-Invoices-and/m-p/3143224#M112317</link>
      <description>&lt;P&gt;Remove the 'Invoices and Payments'...just keep [Inv. Post. Dt.]&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2023 19:21:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-DAX-to-handle-Payments-Applied-to-Invoices-and/m-p/3143224#M112317</guid>
      <dc:creator>BrianConnelly</dc:creator>
      <dc:date>2023-03-20T19:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for DAX to handle Payments Applied to Invoices and Calculate Outstanding Amount</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-DAX-to-handle-Payments-Applied-to-Invoices-and/m-p/3143448#M112345</link>
      <description>&lt;DIV&gt;So what you originally suggested works overall, but just not at the row level as shown in my last screenshot...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;SUMX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;SUMMARIZE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Invoices and Payments'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;'Invoices and Payments'&lt;/SPAN&gt;&lt;SPAN&gt;[Inv No.]&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;[Inv. Post. Dt.]&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;[Date]&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;"InvoiceAmount"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;[Invoice Amount]&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;"InvoicePayment"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;[Applied Amount]&lt;/SPAN&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;SPAN&gt;[InvoiceAmount]&lt;/SPAN&gt;&lt;SPAN&gt;+&lt;/SPAN&gt;&lt;SPAN&gt;[InvoicePayment]&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I got past the error thanks to your latest suggestion, but it looks like the filter context is off as it produces large and incorrect values on both rows and total when I use the DAX at the bottom here.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I've tried creating my variable table with both [Inv. Post. Dt.] and [Applied Date].&amp;nbsp; I think the latter is probably what you meant, as the fomer is the date of the invoice, and the latter is the date that&amp;nbsp; they payment is applied.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I've also tried joining the variableTable to my main table based upon Invoice Number.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;It seems like this is getting sums for lots of stuff in the variableTable, rather than just the invoice I'm looking at?&lt;BR /&gt;It seems like ALLSELECTED should know which invoice is in context, especially if I have a relationship defined.&lt;BR /&gt;Do I need to use RELATED or something like that?&amp;nbsp; Sorry, I'm pretty new to this kind of DAX.&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Outstanding Amount = &lt;/SPAN&gt;&lt;SPAN&gt;SUMX(FILTER(ALLSELECTED(variableTable),[Applied Date]&amp;lt;=MAX([Applied Date])),[InvoiceAmount]+[InvoicePayment])&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 20 Mar 2023 21:49:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-DAX-to-handle-Payments-Applied-to-Invoices-and/m-p/3143448#M112345</guid>
      <dc:creator>Karl-D</dc:creator>
      <dc:date>2023-03-20T21:49:50Z</dc:date>
    </item>
  </channel>
</rss>

