<?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 value from another table using intermediary table in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221613#M52778</link>
    <description>&lt;P&gt;I'm using the Microsoft provided Adventureworks data for SQL Server in a Power BI project.&amp;nbsp; I want to get the unit cost of a product but it requires three tables.&amp;nbsp; I was going to create a new column in the SalesOrderDetail to calculate the UnitCost by getting the StandardCost during the correct period (StartDate, EndDate) from the ProductCostHistory table.&amp;nbsp; But I don't know how to reference all three tables.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I need the SalesOrderHeader for the OrderDate and the SalesOrderDetail for the ProductID so that I get the correct historical cost.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the SQL query which gives me the proper relationships.&amp;nbsp;&lt;/P&gt;&lt;P&gt;SELECT SOD.UnitPrice, SOH.OrderDate, PCH.StandardCost, PCH.StartDate, PCH.EndDate, PCH.ProductID, SOD.ProductID&lt;BR /&gt;FROM sales.SalesOrderDetail sod&lt;BR /&gt;JOIN sales.SalesOrderHeader soh on soh.SalesOrderID = sod.SalesOrderID&lt;BR /&gt;JOIN [Production].[ProductCostHistory] pch on pch.ProductID = sod.ProductID&lt;BR /&gt;AND soh.OrderDate BETWEEN pch.startdate AND pch.EndDate&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any guidance would be appreciated.&amp;nbsp; Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Dec 2021 00:42:21 GMT</pubDate>
    <dc:creator>jjolk</dc:creator>
    <dc:date>2021-12-06T00:42:21Z</dc:date>
    <item>
      <title>Get value from another table using intermediary table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221613#M52778</link>
      <description>&lt;P&gt;I'm using the Microsoft provided Adventureworks data for SQL Server in a Power BI project.&amp;nbsp; I want to get the unit cost of a product but it requires three tables.&amp;nbsp; I was going to create a new column in the SalesOrderDetail to calculate the UnitCost by getting the StandardCost during the correct period (StartDate, EndDate) from the ProductCostHistory table.&amp;nbsp; But I don't know how to reference all three tables.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I need the SalesOrderHeader for the OrderDate and the SalesOrderDetail for the ProductID so that I get the correct historical cost.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the SQL query which gives me the proper relationships.&amp;nbsp;&lt;/P&gt;&lt;P&gt;SELECT SOD.UnitPrice, SOH.OrderDate, PCH.StandardCost, PCH.StartDate, PCH.EndDate, PCH.ProductID, SOD.ProductID&lt;BR /&gt;FROM sales.SalesOrderDetail sod&lt;BR /&gt;JOIN sales.SalesOrderHeader soh on soh.SalesOrderID = sod.SalesOrderID&lt;BR /&gt;JOIN [Production].[ProductCostHistory] pch on pch.ProductID = sod.ProductID&lt;BR /&gt;AND soh.OrderDate BETWEEN pch.startdate AND pch.EndDate&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any guidance would be appreciated.&amp;nbsp; Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 00:42:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221613#M52778</guid>
      <dc:creator>jjolk</dc:creator>
      <dc:date>2021-12-06T00:42:21Z</dc:date>
    </item>
    <item>
      <title>Re: Get value from another table using intermediary table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221627#M52779</link>
      <description>&lt;P&gt;Can you show your relationship diagram?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I download the &lt;A href="https://github.com/microsoft/powerbi-desktop-samples/blob/main/DAX/Adventure%20Works%20DW%202020.pbix" target="_blank"&gt;AdventureWorks .pbix file&lt;/A&gt; it looks like this:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 01:02:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221627#M52779</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2021-12-06T01:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: Get value from another table using intermediary table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221632#M52781</link>
      <description>&lt;P&gt;Yes, unfortunately there are multiple versions of the Adventureworks database.&amp;nbsp; Here's the data model for the one I'm using.&amp;nbsp; Let me know if the screenshot below works.&amp;nbsp; &amp;nbsp;I know I'm ignoring the Products table, but since I have ProductID in the SalesOrderDetail and ProductCostHistory table, at least in SQL Server, I'm okay.&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;</description>
      <pubDate>Mon, 06 Dec 2021 01:10:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221632#M52781</guid>
      <dc:creator>jjolk</dc:creator>
      <dc:date>2021-12-06T01:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Get value from another table using intermediary table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221649#M52782</link>
      <description>&lt;P&gt;There are a variety of ways to traverse relationships but if you want to avoid worrying about stuff like context transitions and expanded tables, then you can go with a straightforward filter approach that doesn't use the relationships.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not super efficient but it should work:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;UnitCost =
VAR ProductID = SalesOrderDetail[ProductID]
VAR OrderDate = SalesOrderDetail[OrderDate]
RETURN
    MAXX (
        FILTER (
            ProductCostHistory,
            ProductCostHistory[ProductID] = ProductID
                &amp;amp;&amp;amp; ProductCostHistory[StartDate] &amp;lt;= OrderDate
                &amp;amp;&amp;amp; ProductCostHistory[EndDate] &amp;gt;= OrderDate
        ),
        ProductCostHistory[StandardCost]
    )&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 06 Dec 2021 01:22:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221649#M52782</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2021-12-06T01:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: Get value from another table using intermediary table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221657#M52783</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="343534" data-lia-user-login="jjolk" class="lia-mention lia-mention-user"&gt;jjolk&lt;/a&gt;&amp;nbsp; Is it kindly possible to post the pbix please?&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 01:32:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221657#M52783</guid>
      <dc:creator>smpa01</dc:creator>
      <dc:date>2021-12-06T01:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: Get value from another table using intermediary table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221663#M52785</link>
      <description>&lt;P&gt;Well, I was too quick to accept the solution.&amp;nbsp; Reading it through, it seemed perfect.&amp;nbsp; However, Power BI has other thoughts on the matter.&amp;nbsp; I get the following error message.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Not sure why it doesn't like the statement since it is using MAXX.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 01:34:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221663#M52785</guid>
      <dc:creator>jjolk</dc:creator>
      <dc:date>2021-12-06T01:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: Get value from another table using intermediary table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221665#M52786</link>
      <description>&lt;P&gt;Are you trying to define this as a measure? Your original post asked for a calculated column.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 01:35:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221665#M52786</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2021-12-06T01:35:17Z</dc:date>
    </item>
    <item>
      <title>Re: Get value from another table using intermediary table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221685#M52787</link>
      <description>&lt;P&gt;&lt;EM&gt;Pedantic side note:&lt;/EM&gt;&amp;nbsp;The sale order date isn't really the best match for looking up a historical price. Ideally, you'd use the purchase date but that requires more detailed inventory tracking than this model appears to support. Assuming inventory turnover is relatively quick, it's not a terrible approximation.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 01:43:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221685#M52787</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2021-12-06T01:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: Get value from another table using intermediary table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221734#M52788</link>
      <description>&lt;P&gt;You are correct, I did actually try this first as a measure even though I meant to create a column.&amp;nbsp; I went back and tried it as a column and received a similar message.&amp;nbsp; Note, I made a couple of change to the script.&amp;nbsp; I referenced SalesOderHeader for [OrderDate] and I changed the date comparisons so [OrderDate] is between the start and end dates.&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;</description>
      <pubDate>Mon, 06 Dec 2021 02:09:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221734#M52788</guid>
      <dc:creator>jjolk</dc:creator>
      <dc:date>2021-12-06T02:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Get value from another table using intermediary table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221752#M52789</link>
      <description>&lt;P&gt;Since OrderDate is coming from a different table, try this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;VAR OrderDate = RELATED ( SalesOrderHeader[OrderDate] )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think I already had the date inequalities correct. Assuming StartDate &amp;lt;= EndDate, you have&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;OrderDate &amp;lt;= StartDate &amp;lt;= EndDate &amp;lt;= OrderDate&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;which can only be true if these are all equal.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 02:19:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221752#M52789</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2021-12-06T02:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: Get value from another table using intermediary table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221800#M52790</link>
      <description>&lt;P&gt;Thank you. Added the Related function fixed it.&amp;nbsp; This gives me a solution that I can now explore and try to make sure I understand it better. I appreciate your help.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Julie&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 02:41:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-value-from-another-table-using-intermediary-table/m-p/2221800#M52790</guid>
      <dc:creator>jjolk</dc:creator>
      <dc:date>2021-12-06T02:41:09Z</dc:date>
    </item>
  </channel>
</rss>

