<?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: Should I use temp table in my measures to find the median value? in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Should-I-use-temp-table-in-my-measures-to-find-the-median-value/m-p/2125291#M48740</link>
    <description>&lt;P&gt;Just for future reference, here is my PBI version.&amp;nbsp; It is very similar to Daniel.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;#Age_median = 
var start_of_month = SELECTEDVALUE('_End of Month Dates'[Month Start]) //BoM)
var end_of_month = EOMONTH(start_of_month,0)

var table_unpaid =  //A = invocie date &amp;lt;= end_month , B = payment date &amp;gt; end_monht, C = payment is blank
                    // AB + AC
                    FILTER('Table 1', ('Table 1'[Invoice date]&amp;lt;=end_of_month &amp;amp;&amp;amp; 'Table 1'[Payment date] &amp;gt; end_of_month)
                                    || ('Table 1'[Invoice date]&amp;lt;=end_of_month &amp;amp;&amp;amp; ISBLANK('Table 1'[Payment date]))
                                    )
var table_age_inMonth = ADDCOLUMNS(table_unpaid, "Ar_age_EOM", 
                                   switch(TRUE(),
                                            ISBLANK([Payment date]), DATEDIFF( [Invoice date], end_of_month, DAY),
                                            [Payment date]&amp;gt;end_of_month, DATEDIFF( [Invoice date], end_of_month, DAY),  
                                            DATEDIFF( [Invoice date],[Payment date], DAY) )
                                    )   
            
return
MEDIANX(table_age_inMonth, [Ar_age_EOM])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 09 Oct 2021 19:53:01 GMT</pubDate>
    <dc:creator>AlohaPaul</dc:creator>
    <dc:date>2021-10-09T19:53:01Z</dc:date>
    <item>
      <title>Should I use temp table in my measures to find the median value?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Should-I-use-temp-table-in-my-measures-to-find-the-median-value/m-p/2122609#M48684</link>
      <description>&lt;P&gt;Hi PowerBI masters,&lt;/P&gt;&lt;P&gt;Any idea how the DAX formula I need for this report needs below?&amp;nbsp; &amp;nbsp;It seems that I have to create measures with dynamic temp table in its DAX to solve the problem.&amp;nbsp; &amp;nbsp;Honestly, I am not sure.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all in advance for your help!&lt;BR /&gt;I have a table of invoices with its invoice dates and payment dates.&amp;nbsp; &amp;nbsp;Plus a calculated column: Final AR age (= Payment date - Invoice date).&amp;nbsp;&amp;nbsp;&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;&lt;P&gt;I am trying to design a report like this one below:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which is the summary of the calculation here&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;For example, for invoice #2, on Aug 31, its AR age = Aug 31 - July 5 = 57.&amp;nbsp; However,&amp;nbsp; in September, it is no longer outstanding.&amp;nbsp; Therefore it is excluded from the median outstanding invoice's AR calculation.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Although I can add all the calculated columns (in blue), I would prefer a more dynamic approach since I like a report for the last 24 months.&amp;nbsp; But the AR Age for each month-end needs to be calculated dynamically to get the correct median AR age.&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;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 21:49:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Should-I-use-temp-table-in-my-measures-to-find-the-median-value/m-p/2122609#M48684</guid>
      <dc:creator>AlohaPaul</dc:creator>
      <dc:date>2021-10-07T21:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: Should I use temp table in my measures to find the median value?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Should-I-use-temp-table-in-my-measures-to-find-the-median-value/m-p/2123051#M48686</link>
      <description>&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 02:55:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Should-I-use-temp-table-in-my-measures-to-find-the-median-value/m-p/2123051#M48686</guid>
      <dc:creator>wdx223_Daniel</dc:creator>
      <dc:date>2021-10-08T02:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: Should I use temp table in my measures to find the median value?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Should-I-use-temp-table-in-my-measures-to-find-the-median-value/m-p/2125290#M48739</link>
      <description>&lt;P&gt;Thank you, Daniel!&lt;/P&gt;</description>
      <pubDate>Sat, 09 Oct 2021 19:48:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Should-I-use-temp-table-in-my-measures-to-find-the-median-value/m-p/2125290#M48739</guid>
      <dc:creator>AlohaPaul</dc:creator>
      <dc:date>2021-10-09T19:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: Should I use temp table in my measures to find the median value?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Should-I-use-temp-table-in-my-measures-to-find-the-median-value/m-p/2125291#M48740</link>
      <description>&lt;P&gt;Just for future reference, here is my PBI version.&amp;nbsp; It is very similar to Daniel.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;#Age_median = 
var start_of_month = SELECTEDVALUE('_End of Month Dates'[Month Start]) //BoM)
var end_of_month = EOMONTH(start_of_month,0)

var table_unpaid =  //A = invocie date &amp;lt;= end_month , B = payment date &amp;gt; end_monht, C = payment is blank
                    // AB + AC
                    FILTER('Table 1', ('Table 1'[Invoice date]&amp;lt;=end_of_month &amp;amp;&amp;amp; 'Table 1'[Payment date] &amp;gt; end_of_month)
                                    || ('Table 1'[Invoice date]&amp;lt;=end_of_month &amp;amp;&amp;amp; ISBLANK('Table 1'[Payment date]))
                                    )
var table_age_inMonth = ADDCOLUMNS(table_unpaid, "Ar_age_EOM", 
                                   switch(TRUE(),
                                            ISBLANK([Payment date]), DATEDIFF( [Invoice date], end_of_month, DAY),
                                            [Payment date]&amp;gt;end_of_month, DATEDIFF( [Invoice date], end_of_month, DAY),  
                                            DATEDIFF( [Invoice date],[Payment date], DAY) )
                                    )   
            
return
MEDIANX(table_age_inMonth, [Ar_age_EOM])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Oct 2021 19:53:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Should-I-use-temp-table-in-my-measures-to-find-the-median-value/m-p/2125291#M48740</guid>
      <dc:creator>AlohaPaul</dc:creator>
      <dc:date>2021-10-09T19:53:01Z</dc:date>
    </item>
  </channel>
</rss>

