<?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: Need help to make calculations based on a selection of matching rows in a related table in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-to-make-calculations-based-on-a-selection-of-matching/m-p/960325#M11193</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="211673" data-lia-user-login="larsm11" class="lia-mention lia-mention-user"&gt;larsm11&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Column = 
VAR __amounts = 
    CALCULATETABLE( 
        {
            MIN( Postings[Amount] ),
            MIN( Postings[Amount] ) 
        }
    )
RETURN 
CALCULATE(
    DATEDIFF( MIN( Postings[Date] ), MAX( Postings[Date] ), DAY ),
    TREATAS( __amounts, Postings[Amount] )
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;Best Regards,&lt;BR /&gt;Mariusz&lt;BR /&gt;&lt;BR /&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;STRONG&gt;&lt;I&gt;Accepting it as the solution&lt;/I&gt;&lt;/STRONG&gt;.&lt;BR /&gt;&lt;BR /&gt;Please feel free to connect with me.&lt;BR /&gt;&lt;A href="https://www.linkedin.com/in/mariusz-repczynski-065a7362/" target="_blank"&gt; LinkedIn &lt;/A&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Mar 2020 10:39:35 GMT</pubDate>
    <dc:creator>Mariusz</dc:creator>
    <dc:date>2020-03-05T10:39:35Z</dc:date>
    <item>
      <title>Need help to make calculations based on a selection of matching rows in a related table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-to-make-calculations-based-on-a-selection-of-matching/m-p/953950#M10838</link>
      <description>&lt;P&gt;Hi - I'm relatively new to DAX, and I have the following issue that I cannot get passed.&lt;/P&gt;&lt;P&gt;I have a table with invoices, and an related table (they share InvoiceID) with all ledger postings related to these invoices.&lt;/P&gt;&lt;P&gt;I want to create a custom column in the Invoice table with payment days (using DAX) based on the following rationale:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Find all postings in the Postings table with matching invoiceID as the row in the invoice table (e.g. 77536391 in the sample)&lt;/LI&gt;&lt;LI&gt;Calculate the days between date of the posting with the highest &lt;U&gt;&lt;STRONG&gt;positive&lt;/STRONG&gt; &lt;/U&gt;Amount value and the matching posting with the highest &lt;STRONG&gt;&lt;U&gt;negative&lt;/U&gt; &lt;/STRONG&gt;amount&lt;/LI&gt;&lt;LI&gt;Add the calculated number to the Payment Days custom column in the Invoice table&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Hopeful someone can help.&lt;/P&gt;&lt;P&gt;/LarsM&lt;/P&gt;&lt;P&gt;Invoice and Postings table extract.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Mar 2020 01:34:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-to-make-calculations-based-on-a-selection-of-matching/m-p/953950#M10838</guid>
      <dc:creator>larsm11</dc:creator>
      <dc:date>2020-03-01T01:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to make calculations based on a selection of matching rows in a related table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-to-make-calculations-based-on-a-selection-of-matching/m-p/960325#M11193</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="211673" data-lia-user-login="larsm11" class="lia-mention lia-mention-user"&gt;larsm11&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Column = 
VAR __amounts = 
    CALCULATETABLE( 
        {
            MIN( Postings[Amount] ),
            MIN( Postings[Amount] ) 
        }
    )
RETURN 
CALCULATE(
    DATEDIFF( MIN( Postings[Date] ), MAX( Postings[Date] ), DAY ),
    TREATAS( __amounts, Postings[Amount] )
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;Best Regards,&lt;BR /&gt;Mariusz&lt;BR /&gt;&lt;BR /&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;STRONG&gt;&lt;I&gt;Accepting it as the solution&lt;/I&gt;&lt;/STRONG&gt;.&lt;BR /&gt;&lt;BR /&gt;Please feel free to connect with me.&lt;BR /&gt;&lt;A href="https://www.linkedin.com/in/mariusz-repczynski-065a7362/" target="_blank"&gt; LinkedIn &lt;/A&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 10:39:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-to-make-calculations-based-on-a-selection-of-matching/m-p/960325#M11193</guid>
      <dc:creator>Mariusz</dc:creator>
      <dc:date>2020-03-05T10:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to make calculations based on a selection of matching rows in a related table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-to-make-calculations-based-on-a-selection-of-matching/m-p/960419#M11203</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;[Payment Days] =  // calc column
VAR __maxAmount = 
	MAXX(
		RELATEDTABLE( Postings ),
		Postings[Amount]
	)
var __minAmount =
	MINX(
		RELATEDTABLE( Postings ),
		Postings[Amount]
	)
var __amountsAreCorrect =
	__maxAmount &amp;gt; 0
	&amp;amp;&amp;amp; ( __maxAmount + __minAmount = 0 )
var __dayOfMaxAmount =
	CALCULATE(
		VALUES( Postings[Date] ),
		Postings[Amount] = __maxAmount
	)
var __dayOfMinAmount =
	CALCULATE(
		VALUES( Postings[Date] ),
		Postings[Amount] = __minAmount
	)
var __onlyOnePairOfDatesFound =
	COUNTROWS( __dayOfMinAmount ) = 1
	&amp;amp;&amp;amp;
	1 = COUNTROWS( __dayOfMaxAmount )
var __shouldCalculate =
	__amountsAreCorrect &amp;amp;&amp;amp; __onlyOnePairOfDatesFound
RETURN
if( __shouldCalculate, int(__dayOfMaxAmount - __dayOfMinAmount) )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This should cover all the problems you might have in the Postings table. For instance, there could not be a matching negative amount.. and the likes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best&lt;/P&gt;
&lt;P&gt;D&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 11:59:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-to-make-calculations-based-on-a-selection-of-matching/m-p/960419#M11203</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-05T11:59:20Z</dc:date>
    </item>
  </channel>
</rss>

