<?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: Calculate days outstanding for invoices in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-days-outstanding-for-invoices/m-p/1375067#M25072</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// The Calendar should NOT be connected
// to Payments. Payments should be hidden.
// All calculations on Payments should
// be exposed solely through measures.
// The Calendar will be connected to
// Invoices on the Invoices[Date] field.
// of course Invoices will be connected
// to Payments on the invoice number.

[Days Outstanding] =
// This will return the days
// since the invoice date
// until TODAY() if the invoice
// has not had any payment against it.
// If it has had at least one payment,
// BLANK will be returned. If there are
// many invoices from Invoices visible
// in the current context, -1 will be
// returned (you can then change it to
// any value you think makes sense).
var __today = TODAY()
var __onlyOneInvoiceVisible =
    HASONEVALUE( Invoices[InvoiceNumber] )
var __result =
    if( __onlyOneInvoiceVisible,
        
        var __noPaymentsPresent =
            CALCULATE(
                ISEMPTY( Payments ),
                ALL( Payments ),
                VALUES( Invoices[InvoiceNumber] )
            )
        var __daysOutstanding =
            if( __noPaymentsPresent,
                // get the date of the invoice
                // and find the number of days
                // since then until __today
                var __invoiceDate =
                    SELECTEDVALUE( Invoices[Date] )
                return
                    INT( __today - __invoiceDate )
            )
        return
            __daysOutstanding,
        // output when there are many invoices in scope
        -1
    )
return
    __result&lt;/LI-CODE&gt;&lt;P&gt;It's now easy using the measure above and a disconnected table with the age brackets to calculate the number of invoices (dynamically) that fall into each of these brackets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Sep 2020 12:00:16 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-09-16T12:00:16Z</dc:date>
    <item>
      <title>Calculate days outstanding for invoices</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-days-outstanding-for-invoices/m-p/1374498#M25068</link>
      <description>&lt;P&gt;Hi all!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 3 tabels with data:&lt;/P&gt;&lt;P&gt;- Invoices &amp;gt; all the data about the invoice we send to our customers&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;(invoices[date])&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;(invoices[amount])&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;(invoices[customernumber])&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;(invoices[invoicenumber])&lt;/P&gt;&lt;P&gt;- Payments &amp;gt; all the data about the payments we receive&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;(payments[date])&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;(payments[amount])&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;(payments[customernumber])&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;(payments[invoicenumber])&lt;/P&gt;&lt;P&gt;- Calander &amp;gt; all the dates ect.&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;(calander[date])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to calculate the days outstanding for the invoices that have not been paid on any date. I also would like to categorise them into categories like 0 - 30 days outstanding, 31-60 days outstanding ect&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have searched through the community but could not find the right sollution. Who can help me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards en thank you very much in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Simon Kruizinga&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 08:44:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-days-outstanding-for-invoices/m-p/1374498#M25068</guid>
      <dc:creator>kruizing</dc:creator>
      <dc:date>2020-09-16T08:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate days outstanding for invoices</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-days-outstanding-for-invoices/m-p/1375026#M25070</link>
      <description>&lt;P&gt;Assuming that there's some sort of relationship between the two tables, then something like this as a conditional column:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Age = if(Payments[date] &amp;lt;&amp;gt; blank(), datediff(Invoices[date],today(),day),blank()) ought to work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can then use groupings to get 0-30, 31-60 etc, or something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;AgeGroup = if([Age]&amp;lt;31,"0-30"),if([Age]&amp;lt;61,"31-60","61+"))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally I'd do this in Power Query, but that might be a bit complicated if you get more than one payment on an invoice&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 11:42:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-days-outstanding-for-invoices/m-p/1375026#M25070</guid>
      <dc:creator>jthomson</dc:creator>
      <dc:date>2020-09-16T11:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate days outstanding for invoices</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-days-outstanding-for-invoices/m-p/1375067#M25072</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// The Calendar should NOT be connected
// to Payments. Payments should be hidden.
// All calculations on Payments should
// be exposed solely through measures.
// The Calendar will be connected to
// Invoices on the Invoices[Date] field.
// of course Invoices will be connected
// to Payments on the invoice number.

[Days Outstanding] =
// This will return the days
// since the invoice date
// until TODAY() if the invoice
// has not had any payment against it.
// If it has had at least one payment,
// BLANK will be returned. If there are
// many invoices from Invoices visible
// in the current context, -1 will be
// returned (you can then change it to
// any value you think makes sense).
var __today = TODAY()
var __onlyOneInvoiceVisible =
    HASONEVALUE( Invoices[InvoiceNumber] )
var __result =
    if( __onlyOneInvoiceVisible,
        
        var __noPaymentsPresent =
            CALCULATE(
                ISEMPTY( Payments ),
                ALL( Payments ),
                VALUES( Invoices[InvoiceNumber] )
            )
        var __daysOutstanding =
            if( __noPaymentsPresent,
                // get the date of the invoice
                // and find the number of days
                // since then until __today
                var __invoiceDate =
                    SELECTEDVALUE( Invoices[Date] )
                return
                    INT( __today - __invoiceDate )
            )
        return
            __daysOutstanding,
        // output when there are many invoices in scope
        -1
    )
return
    __result&lt;/LI-CODE&gt;&lt;P&gt;It's now easy using the measure above and a disconnected table with the age brackets to calculate the number of invoices (dynamically) that fall into each of these brackets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 12:00:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-days-outstanding-for-invoices/m-p/1375067#M25072</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-09-16T12:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate days outstanding for invoices</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-days-outstanding-for-invoices/m-p/1377259#M25131</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;Thank you very much for your contribution!&lt;/P&gt;&lt;P&gt;I have tried your sollution but unfortunatly it didn't worked as I hoped. I only get the result of -1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could this have something to do with the fact that multiple records can exist for one invoice number? Also in the table of payments, multiple records can exist for one invoice.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 09:33:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-days-outstanding-for-invoices/m-p/1377259#M25131</guid>
      <dc:creator>kruizing</dc:creator>
      <dc:date>2020-09-17T09:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate days outstanding for invoices</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-days-outstanding-for-invoices/m-p/1377391#M25137</link>
      <description>Invoices is a dimension, so no duplicates are allowed. Duplicates can only exist in fact tables. This is one of the golden rules of dimensional modeling. You get -1 because you are violating the rules.</description>
      <pubDate>Thu, 17 Sep 2020 10:29:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-days-outstanding-for-invoices/m-p/1377391#M25137</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-09-17T10:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate days outstanding for invoices</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-days-outstanding-for-invoices/m-p/1418350#M26347</link>
      <description>&lt;P&gt;I am sorry for violating the rules. I'm pretty new into BI , please be patient with me&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created an extra table for the invoices with only 1 unique record for each invoice. In this table I have the same data as before. All the movements on the invoices and payments are in seperate tables. I have adjusted your script in one of your previous posts. Unfortunatly without any result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I doing wrong?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 13:27:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-days-outstanding-for-invoices/m-p/1418350#M26347</guid>
      <dc:creator>kruizing</dc:creator>
      <dc:date>2020-10-07T13:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate days outstanding for invoices</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-days-outstanding-for-invoices/m-p/1418535#M26354</link>
      <description>If you still get -1, then you know why - it's all in the code. If more than 1 invoice is visible in the current context, you'll get -1.&lt;BR /&gt;&lt;BR /&gt;Please read this (&lt;A href="https://docs.microsoft.com/en-us/power-bi/guidance/star-schema" target="_blank"&gt;https://docs.microsoft.com/en-us/power-bi/guidance/star-schema&lt;/A&gt;) to know how to correctly model data for Power BI.&lt;BR /&gt;&lt;BR /&gt;If you can, please place a link to a PBI file here so that I can take a look. You don't have to have real data in it. Just put some data, even fully artificial, that is REPRESENTATIVE of the problem at hand. I'll take a look.&lt;BR /&gt;&lt;BR /&gt;Cheers.</description>
      <pubDate>Wed, 07 Oct 2020 14:22:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-days-outstanding-for-invoices/m-p/1418535#M26354</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-10-07T14:22:07Z</dc:date>
    </item>
  </channel>
</rss>

