<?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 Get a corresponding price from another table using relationship through item table in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-a-corresponding-price-from-another-table-using-relationship/m-p/2921638#M95817</link>
    <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this pretty complex problem (at least for me) that I can't seem to solve by myself. So basically I have this table called "Latest purchase price", which has information about every items latest purchased. I also have an item table and then I have a trade agreements table that contains information about every item's trade agreements for different purchase quantities, thus the relationship between that table and item table is many-to-one. I'll post a picture here about the data model if that helps.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I want to compare latest purchase price to the price that we have in trade agreements thus I need to get the corresponding value from the trade agreements table for the latest purchase. I'll post a mockup data here also so that you can try it yourself.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to do this using summarize columns and sumx. The logic is that once I have the virtual table with trade agreements for given item, I can use filter condition to filter it only contain values where purchased qty is equal or greater than fromqty in trade agreements table. Still it is ambiguous so using minx I want to just get one value which should be correct. But as you can see from picture bellow my dax query is not working...&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Trade agreement price = 
 var latest_qty = MAXX('Latest Purch Prices', 'Latest Purch Prices'[OrderedQty])
 var trade_agreement_qty = 
 FILTER(SUMMARIZECOLUMNS(
     vDimItem[ItemID], 
    TradeAgreements[AMOUNT], 
    TradeAgreements[QUANTITYAMOUNTFROM]),
    TradeAgreements[QUANTITYAMOUNTFROM] &amp;lt;= latest_qty)
 
 return
MINX(trade_agreement_qty, TradeAgreements[QUANTITYAMOUNTFROM])&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Latest Purch Price Table:

ID	ITEM	PRICE	ORDEREDQTY
1	1234	1	1
2	1235	2	10
3	1236	11	3&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;vDimItem:

ID	ITEMID
1	1234
2	1235
3	1236&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;TradeAgreements:

ITEMRELATION	FROMQTY	AMOUNT
1234	0	1
1235	0	5
1235	10	2
1236	0	10
1236	5	5
1236	10	2&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Goal/Result:

ID	ITEM	PRICE	ORDEREDQTY	TRADEAGREEMENT PRICE	Difference
1	1234	1	1	1	0
2	1235	2	10	2	0
3	1236	11	3	2	-1
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Nov 2022 12:38:55 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-11-22T12:38:55Z</dc:date>
    <item>
      <title>Get a corresponding price from another table using relationship through item table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-a-corresponding-price-from-another-table-using-relationship/m-p/2921638#M95817</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this pretty complex problem (at least for me) that I can't seem to solve by myself. So basically I have this table called "Latest purchase price", which has information about every items latest purchased. I also have an item table and then I have a trade agreements table that contains information about every item's trade agreements for different purchase quantities, thus the relationship between that table and item table is many-to-one. I'll post a picture here about the data model if that helps.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I want to compare latest purchase price to the price that we have in trade agreements thus I need to get the corresponding value from the trade agreements table for the latest purchase. I'll post a mockup data here also so that you can try it yourself.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to do this using summarize columns and sumx. The logic is that once I have the virtual table with trade agreements for given item, I can use filter condition to filter it only contain values where purchased qty is equal or greater than fromqty in trade agreements table. Still it is ambiguous so using minx I want to just get one value which should be correct. But as you can see from picture bellow my dax query is not working...&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Trade agreement price = 
 var latest_qty = MAXX('Latest Purch Prices', 'Latest Purch Prices'[OrderedQty])
 var trade_agreement_qty = 
 FILTER(SUMMARIZECOLUMNS(
     vDimItem[ItemID], 
    TradeAgreements[AMOUNT], 
    TradeAgreements[QUANTITYAMOUNTFROM]),
    TradeAgreements[QUANTITYAMOUNTFROM] &amp;lt;= latest_qty)
 
 return
MINX(trade_agreement_qty, TradeAgreements[QUANTITYAMOUNTFROM])&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Latest Purch Price Table:

ID	ITEM	PRICE	ORDEREDQTY
1	1234	1	1
2	1235	2	10
3	1236	11	3&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;vDimItem:

ID	ITEMID
1	1234
2	1235
3	1236&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;TradeAgreements:

ITEMRELATION	FROMQTY	AMOUNT
1234	0	1
1235	0	5
1235	10	2
1236	0	10
1236	5	5
1236	10	2&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Goal/Result:

ID	ITEM	PRICE	ORDEREDQTY	TRADEAGREEMENT PRICE	Difference
1	1234	1	1	1	0
2	1235	2	10	2	0
3	1236	11	3	2	-1
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 12:38:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-a-corresponding-price-from-another-table-using-relationship/m-p/2921638#M95817</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-11-22T12:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: Get a corresponding price from another table using relationship through item table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-a-corresponding-price-from-another-table-using-relationship/m-p/2922067#M95839</link>
      <description>&lt;P&gt;Hi Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Use the "Related" DAX function and get the value from one table to another table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If this post helps, then please consider&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Accept it as the solution, Appreciate your Kudos!!&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 14:55:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-a-corresponding-price-from-another-table-using-relationship/m-p/2922067#M95839</guid>
      <dc:creator>Jayee</dc:creator>
      <dc:date>2022-11-22T14:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Get a corresponding price from another table using relationship through item table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-a-corresponding-price-from-another-table-using-relationship/m-p/2922111#M95843</link>
      <description>&lt;P&gt;Sorry but that does not help since there is one to many relationship there so multiple values would be returned. But actually, I now managed to solve this problem and can share the resolution here if somebody else comes up with a similar problem.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I basically created a new measure that is the latest purchase qty and saved that to a variable. Then I calculate the corresponding quantity from the trade agreements table which is the biggest qty number that is still lower than the sales qty. Then just calculate the price for where the quantity is the same as we have in above explained variable and return the value.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Trade agreement price = 
VAR latest_qty = [Latest purch qty]
VAR corresp_qty =
    CALCULATE (
        MAXX ( TradeAgreements, TradeAgreements[QUANTITYAMOUNTFROM] ),
        TradeAgreements[QUANTITYAMOUNTFROM] &amp;lt;= latest_qty
    )
VAR corresp_price =
    CALCULATE (
        MINX ( TradeAgreements, TradeAgreements[Price Eur] ),
        TradeAgreements[QUANTITYAMOUNTFROM] = corresp_qty
    )
RETURN
    corresp_price&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 15:18:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-a-corresponding-price-from-another-table-using-relationship/m-p/2922111#M95843</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-11-22T15:18:51Z</dc:date>
    </item>
  </channel>
</rss>

