<?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 Calculate a column across multiple tables in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-a-column-across-multiple-tables/m-p/1728468#M35778</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data across multiple tables that I need to summarize. Data links to the same customer name across all sources. It should not calculate for any customer with a blank or zero estimate value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Whole calculation is something like:&lt;/P&gt;&lt;P&gt;Estimate - Open - Invoice - SNI = Adjustment&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example Data 1&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Customer&lt;/TD&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;Estimate&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Customer1&lt;/TD&gt;&lt;TD&gt;4/3/2021&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Customer2&lt;/TD&gt;&lt;TD&gt;4/3/2021&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Customer3&lt;/TD&gt;&lt;TD&gt;4/3/2021&lt;/TD&gt;&lt;TD&gt;35000&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example Data 2&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;CustName&lt;/TD&gt;&lt;TD&gt;ItemID&lt;/TD&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;Open&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Customer1&lt;/TD&gt;&lt;TD&gt;1234&lt;/TD&gt;&lt;TD&gt;3/30/2021&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Customer3&lt;/TD&gt;&lt;TD&gt;1235&lt;/TD&gt;&lt;TD&gt;4/1/2021&lt;/TD&gt;&lt;TD&gt;20000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Customer3&lt;/TD&gt;&lt;TD&gt;1236&lt;/TD&gt;&lt;TD&gt;4/3/2021&lt;/TD&gt;&lt;TD&gt;5000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Customer2&lt;/TD&gt;&lt;TD&gt;1233&lt;/TD&gt;&lt;TD&gt;4/1/2021&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Other tables are similar to Example Data 2 above.&lt;/P&gt;</description>
    <pubDate>Wed, 17 Mar 2021 18:50:31 GMT</pubDate>
    <dc:creator>jjhammer</dc:creator>
    <dc:date>2021-03-17T18:50:31Z</dc:date>
    <item>
      <title>Calculate a column across multiple tables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-a-column-across-multiple-tables/m-p/1728468#M35778</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data across multiple tables that I need to summarize. Data links to the same customer name across all sources. It should not calculate for any customer with a blank or zero estimate value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Whole calculation is something like:&lt;/P&gt;&lt;P&gt;Estimate - Open - Invoice - SNI = Adjustment&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example Data 1&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Customer&lt;/TD&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;Estimate&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Customer1&lt;/TD&gt;&lt;TD&gt;4/3/2021&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Customer2&lt;/TD&gt;&lt;TD&gt;4/3/2021&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Customer3&lt;/TD&gt;&lt;TD&gt;4/3/2021&lt;/TD&gt;&lt;TD&gt;35000&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example Data 2&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;CustName&lt;/TD&gt;&lt;TD&gt;ItemID&lt;/TD&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;Open&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Customer1&lt;/TD&gt;&lt;TD&gt;1234&lt;/TD&gt;&lt;TD&gt;3/30/2021&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Customer3&lt;/TD&gt;&lt;TD&gt;1235&lt;/TD&gt;&lt;TD&gt;4/1/2021&lt;/TD&gt;&lt;TD&gt;20000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Customer3&lt;/TD&gt;&lt;TD&gt;1236&lt;/TD&gt;&lt;TD&gt;4/3/2021&lt;/TD&gt;&lt;TD&gt;5000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Customer2&lt;/TD&gt;&lt;TD&gt;1233&lt;/TD&gt;&lt;TD&gt;4/1/2021&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Other tables are similar to Example Data 2 above.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Mar 2021 18:50:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-a-column-across-multiple-tables/m-p/1728468#M35778</guid>
      <dc:creator>jjhammer</dc:creator>
      <dc:date>2021-03-17T18:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a column across multiple tables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-a-column-across-multiple-tables/m-p/1728592#M35782</link>
      <description>&lt;P&gt;You are going to have to give us more of what you are expecting&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="291337" data-lia-user-login="jjhammer" class="lia-mention lia-mention-user"&gt;jjhammer&lt;/a&gt;&amp;nbsp;but let me take a stab at this. You cannot just add columns like that across tables. You'd have to have this absurd DAX measure with a bunch of LOOKUPVALUE functions and that will not perform well at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead you should bring all of this into one table using a method like this:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Create a table in Power Query with unique customer numbers I've shown this in the code presented below.&lt;/LI&gt;
&lt;LI&gt;Merge this [Main Table] with the first table and bring in the data.&lt;/LI&gt;
&lt;LI&gt;Merge this [Main Table] with the second table and bring in the data&lt;/LI&gt;
&lt;LI&gt;repeat for each table.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the result:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;So there are some problems.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Customer 3 has 2 records in Table2, so that caused the 35,000 value in table 1 to get duplicated.&lt;/LI&gt;
&lt;LI&gt;If you grouped table 2 by customer name first, summarizing the "Open" amount, that would work, but, it would remove both the itemID and Dates from that table, which are both different - 1235/1236, 4/1/2021, 4/3/2021.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;The M code to do what I did, assuming your tables are called Table1 and Table2 is this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    Source = List.Combine({Table1[Customer], Table2[CustName]}),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), {"Customer Name"}, null, ExtraValues.Error),
    #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Customer Name", type text}}),
    #"Removed Duplicates" = Table.Distinct(#"Changed Type"),
    #"Merged Queries" = Table.NestedJoin(#"Removed Duplicates", {"Customer Name"}, Table1, {"Customer"}, "Table1", JoinKind.LeftOuter),
    #"Expanded Table1" = Table.ExpandTableColumn(#"Merged Queries", "Table1", {"Date", "Estimate"}, {"Date", "Estimate"}),
    #"Merged Queries1" = Table.NestedJoin(#"Expanded Table1", {"Customer Name"}, Table2, {"CustName"}, "Table2", JoinKind.LeftOuter),
    #"Expanded Table2" = Table.ExpandTableColumn(#"Merged Queries1", "Table2", {"ItemID", "Date", "Open"}, {"ItemID", "Date.1", "Open"})
in
    #"Expanded Table2"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But what really needs to happen is a discussion on how you want this model to work, and this is the challenge of Power BI. It is model driven, and getting the model just right will make your DAX easier, faster, and in some cases, just possible, as a poorely designed model simply won't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to use M code provided in a blank query:&lt;BR /&gt;1) In Power Query, select New Source, then Blank Query&lt;BR /&gt;2) On the Home ribbon, select "Advanced Editor" button&lt;BR /&gt;3) Remove everything you see, then paste the M code I've given you in that box.&lt;BR /&gt;4) Press Done&lt;BR /&gt;5) &lt;A href="https://community.powerbi.com/t5/Community-Blog/Utilizing-M-Code-Samples-Given-as-Solutions-in-Power-Query/ba-p/1147514" target="_blank"&gt;See this article if you need help using this M code in your model.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Mar 2021 20:33:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-a-column-across-multiple-tables/m-p/1728592#M35782</guid>
      <dc:creator>edhans</dc:creator>
      <dc:date>2021-03-17T20:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a column across multiple tables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-a-column-across-multiple-tables/m-p/1728720#M35787</link>
      <description>&lt;P&gt;I think the biggest issue is we recently had a data change. We've been including Adjustments instead of Estimates in calculations and it has worked fine. Data isn't quite as straightforward as my examples (shipped, open, SNI all have multiple lines per customer). If there isn't a simple way to do it, then it'll likely be easier aggregating the data outside of BI into the spreadsheet and importing the adjustment from there.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Mar 2021 21:55:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-a-column-across-multiple-tables/m-p/1728720#M35787</guid>
      <dc:creator>jjhammer</dc:creator>
      <dc:date>2021-03-17T21:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a column across multiple tables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-a-column-across-multiple-tables/m-p/1728741#M35788</link>
      <description>&lt;P&gt;Maybe. If it is a one time thing, sure, do it outside of Power Query. But if it is something you will have to do repeatedly, like weekly, do it in Power Query. I'd rather spend 10hrs coding some Power Query transformations than have to do an hour of work every week with 25 manual transformation steps in a specific way to get a report to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No right answer here. It is a huge "It depends"&lt;/P&gt;</description>
      <pubDate>Wed, 17 Mar 2021 22:05:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-a-column-across-multiple-tables/m-p/1728741#M35788</guid>
      <dc:creator>edhans</dc:creator>
      <dc:date>2021-03-17T22:05:04Z</dc:date>
    </item>
  </channel>
</rss>

