<?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: Average with condition from another table in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-with-condition-from-another-table/m-p/1985934#M43880</link>
    <description>&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Jul 2021 00:35:43 GMT</pubDate>
    <dc:creator>wdx223_Daniel</dc:creator>
    <dc:date>2021-07-29T00:35:43Z</dc:date>
    <item>
      <title>Average with condition from another table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-with-condition-from-another-table/m-p/1985809#M43875</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have spent all day trying various solutions to this and still can't get anything to work.&amp;nbsp; If there is another post with a solution already, please point me to it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've got two tables (examples below), one by person and year code with some other columns.&amp;nbsp; The other is a look-up table, one record per year code with additional codes and descriptors.&amp;nbsp; These are in the model, linked many-to-one by the year code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I need is the average count of person_id per year_part.&amp;nbsp; The person count is NOT distinct, it really is how many total.&amp;nbsp; The year_part seems to group ok by dropping it in the Group part of the visualization.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This almost works&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;mAvgYrPart = divide(count('table1'[person_id]),count('table2'[year_part]))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;What I want to get, using the example, is average = 2&lt;/DIV&gt;&lt;DIV&gt;so that the count of person_id&amp;nbsp;&lt;SPAN&gt;where table1.year_part=10&amp;nbsp; is 4&amp;nbsp; (year_part is actually coming through the relationship to table2 via year_code)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;count of year_part where table2.year_part = 10 is 2&lt;BR /&gt;so average is 4/2 = 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that I would get an average of 1, because the look-up table contains future years so there are actually four records where year_part = 10 and the calculation becomes 4/4 = 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can it count table2.year_part where table2.year_code is less than or equal to max(table1.year_code)?&amp;nbsp; Oh, year_code is a number so MAX should work.&amp;nbsp; Year_part is text, just a label.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Seems it should be easy, but I've tried lookupvalue to pull the year_part to table1 first which kept giving errors, Related gave an error about ambiguity,&amp;nbsp; various combinations using Calculate, Summarize, average, quick measures keep giving errors or simply don't work correctly.&amp;nbsp; Started using DAX last week so not sure what to try next - any suggestions are appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;table 1&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;person_id&lt;/TD&gt;&lt;TD&gt;year_code&lt;/TD&gt;&lt;TD&gt;fact1&lt;/TD&gt;&lt;TD&gt;fact2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;201810&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1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t;201910&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;201920&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;202010&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;202020&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;202110&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;202120&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 28 Jul 2021 22:34:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-with-condition-from-another-table/m-p/1985809#M43875</guid>
      <dc:creator>Jrose</dc:creator>
      <dc:date>2021-07-28T22:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: Average with condition from another table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-with-condition-from-another-table/m-p/1985934#M43880</link>
      <description>&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 00:35:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-with-condition-from-another-table/m-p/1985934#M43880</guid>
      <dc:creator>wdx223_Daniel</dc:creator>
      <dc:date>2021-07-29T00:35:43Z</dc:date>
    </item>
    <item>
      <title>Re: Average with condition from another table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-with-condition-from-another-table/m-p/1987792#M43944</link>
      <description>&lt;P&gt;Awesome! Thank you so much.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the exact formula you showed replaced with actual table and field names and it works perfectly, even with additional groups and filters on the visual.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FYI - the output you show isn't what I needed so I'm not sure how that happened.&amp;nbsp; But as said, it is doing what was needed with the real data, so thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 16:23:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-with-condition-from-another-table/m-p/1987792#M43944</guid>
      <dc:creator>Jrose</dc:creator>
      <dc:date>2021-07-29T16:23:09Z</dc:date>
    </item>
  </channel>
</rss>

