<?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 Joining Multiple Tables with subquery in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Joining-Multiple-Tables-with-subquery/m-p/891530#M21925</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I need to join 3 tables with subquery to count items in each status.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In SQL:&lt;/P&gt;&lt;P&gt;SELECT d.statusCode, d.statusDesc, COUNT(d.statusCode) as Total FROM tbItems a&lt;BR /&gt;&amp;nbsp; &amp;nbsp; INNER JOIN tbStatusHistory b on a.itemid = b.itemid&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and b.statusid = (select top 1 statusid from statusHistory x&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;where x.itemid = a.itemid and x.status_date = (select max(status_date) from statusHistory y where y.itemid = x.itemid))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; INNER JOIN tbStatus d on d.statusCode = b.statusCode&lt;BR /&gt;WHERE START_DATE &amp;gt;= @dtfrom and START_DATE &amp;lt;= @dtto&lt;BR /&gt;GROUP BY d.statusCode, d.statusDesc, d.seqno&lt;BR /&gt;ORDER BY d.seqno&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SQL Results:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.jpg" style="width: 260px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/222895i19A297FACB56A31D/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.jpg" alt="1.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My Chart using &lt;STRONG&gt;HighChart&lt;/STRONG&gt;. I want to do this in Power BI.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="My Chart using HighChart. I want to do this in Power BI" style="width: 387px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/222890i313FF7807F7BD2ED/image-size/large?v=v2&amp;amp;px=999" role="button" title="2.jpg" alt="My Chart using HighChart. I want to do this in Power BI" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;My Chart using HighChart. I want to do this in Power BI&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Jan 2020 07:53:46 GMT</pubDate>
    <dc:creator>Astralpro20</dc:creator>
    <dc:date>2020-01-07T07:53:46Z</dc:date>
    <item>
      <title>Joining Multiple Tables with subquery</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Joining-Multiple-Tables-with-subquery/m-p/891530#M21925</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I need to join 3 tables with subquery to count items in each status.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In SQL:&lt;/P&gt;&lt;P&gt;SELECT d.statusCode, d.statusDesc, COUNT(d.statusCode) as Total FROM tbItems a&lt;BR /&gt;&amp;nbsp; &amp;nbsp; INNER JOIN tbStatusHistory b on a.itemid = b.itemid&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and b.statusid = (select top 1 statusid from statusHistory x&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;where x.itemid = a.itemid and x.status_date = (select max(status_date) from statusHistory y where y.itemid = x.itemid))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; INNER JOIN tbStatus d on d.statusCode = b.statusCode&lt;BR /&gt;WHERE START_DATE &amp;gt;= @dtfrom and START_DATE &amp;lt;= @dtto&lt;BR /&gt;GROUP BY d.statusCode, d.statusDesc, d.seqno&lt;BR /&gt;ORDER BY d.seqno&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SQL Results:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.jpg" style="width: 260px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/222895i19A297FACB56A31D/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.jpg" alt="1.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My Chart using &lt;STRONG&gt;HighChart&lt;/STRONG&gt;. I want to do this in Power BI.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="My Chart using HighChart. I want to do this in Power BI" style="width: 387px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/222890i313FF7807F7BD2ED/image-size/large?v=v2&amp;amp;px=999" role="button" title="2.jpg" alt="My Chart using HighChart. I want to do this in Power BI" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;My Chart using HighChart. I want to do this in Power BI&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 07:53:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Joining-Multiple-Tables-with-subquery/m-p/891530#M21925</guid>
      <dc:creator>Astralpro20</dc:creator>
      <dc:date>2020-01-07T07:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: Joining Multiple Tables with subquery</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Joining-Multiple-Tables-with-subquery/m-p/893962#M21946</link>
      <description>&lt;P&gt;Looking at your SQL you would end up with 2 tables in Power BI&lt;/P&gt;&lt;P&gt;tblItems&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;tblStatusHistory&lt;BR /&gt;the value from the status lookup table with the status codes should be be merged into tlbStatusHistory before you load the data. PowerBI does not mind redundant fields and it is common practice to merge all lookup tables into the transactional tables.&lt;/P&gt;&lt;P&gt;It looks like you want to work with only the most recent record for an item in status history, so you should do a view in sql server that selects the max date and returns only those records. Then load the view into power bi rather than the original table. The rule is to do as much work as possible in sql server... power bi can be complicated enough the way it is.&lt;/P&gt;&lt;P&gt;Then you will end up with your LatestStatusHistory view as your fact table and your tblItem as your dimension table. You should have a 1 to many relationship between items and status history.&amp;nbsp;&lt;BR /&gt;Data models in Power BI should be star schemas, just like in data warehousing. It makes all your DAX MUCH SIMPLER.&lt;/P&gt;&lt;P&gt;This is a big area to talk about. If you'd like to discuss it more send me a day and time and we can do a screen share.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://personalpowerbitrainer.com/" target="_blank"&gt;I'm a personal Power Bi Trainer&lt;/A&gt;&lt;EM&gt; I learn something every time I answer a question&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;The Golden Rules for Power BI&lt;/EM&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Use a Calendar table. A custom Date tables is preferable to using the automatic date/time handling capabilities of Power BI. &lt;A href="https://www.youtube.com/watch?v=FxiAYGbCfAQ" target="_blank"&gt;https://www.youtube.com/watch?v=FxiAYGbCfAQ&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;Build your data model as a Star Schema. Creating a star schema in Power BI is the best practice to improve performance and more importantly, to ensure accurate results! &lt;A href="https://www.youtube.com/watch?v=1Kilya6aUQw" target="_blank"&gt;https://www.youtube.com/watch?v=1Kilya6aUQw&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;Use a small set up sample data when developing. When building your measures and calculated columns always use a small amount of sample data so that it will be easier to confirm that you are getting the right numbers.&lt;/LI&gt;&lt;LI&gt;Store all your intermediate calculations in VARs when you’re writing measures. You can return these intermediate VARs instead of your final result &amp;nbsp;to check on your steps along the way.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 18:58:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Joining-Multiple-Tables-with-subquery/m-p/893962#M21946</guid>
      <dc:creator>kentyler</dc:creator>
      <dc:date>2020-01-08T18:58:15Z</dc:date>
    </item>
  </channel>
</rss>

