<?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 Counting the number of matching items in another column in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-the-number-of-matching-items-in-another-column/m-p/773678#M3814</link>
    <description>&lt;DIV&gt;&lt;P&gt;Hi!&lt;BR /&gt;&lt;BR /&gt;I'm new to Power BI and I wonder if it is possible to count the number of matching elements between two columns. For instance, I have a table that looks like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Item1&lt;/TD&gt;&lt;TD&gt;Item2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Banana&lt;/TD&gt;&lt;TD&gt;Apple&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Peach&lt;/TD&gt;&lt;TD&gt;Apple&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Apple&lt;/TD&gt;&lt;TD&gt;Orange&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;Banana&lt;/TD&gt;&lt;TD&gt;Orange&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;Orange&lt;/TD&gt;&lt;TD&gt;Apple&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that I want to know how many apples there are in total, how many bananas there are in total, how many peaches there are in total, and so on. I don't know if there is a way to do that dynamically (without having to specify the item's name), and then calculate it all in the same query.&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Thu, 22 Aug 2019 22:38:27 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-08-22T22:38:27Z</dc:date>
    <item>
      <title>Counting the number of matching items in another column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-the-number-of-matching-items-in-another-column/m-p/773678#M3814</link>
      <description>&lt;DIV&gt;&lt;P&gt;Hi!&lt;BR /&gt;&lt;BR /&gt;I'm new to Power BI and I wonder if it is possible to count the number of matching elements between two columns. For instance, I have a table that looks like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Item1&lt;/TD&gt;&lt;TD&gt;Item2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Banana&lt;/TD&gt;&lt;TD&gt;Apple&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Peach&lt;/TD&gt;&lt;TD&gt;Apple&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Apple&lt;/TD&gt;&lt;TD&gt;Orange&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;Banana&lt;/TD&gt;&lt;TD&gt;Orange&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;Orange&lt;/TD&gt;&lt;TD&gt;Apple&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that I want to know how many apples there are in total, how many bananas there are in total, how many peaches there are in total, and so on. I don't know if there is a way to do that dynamically (without having to specify the item's name), and then calculate it all in the same query.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 22 Aug 2019 22:38:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-the-number-of-matching-items-in-another-column/m-p/773678#M3814</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-08-22T22:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of matching items in another column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-the-number-of-matching-items-in-another-column/m-p/773827#M3815</link>
      <description>&lt;P&gt;Sure, you should be able to do this although the exact DAX code will vary depending upon what you are specifically trying to accomplish, but as a column calculation, that would look something along the lines of:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Column = 
  VAR __table = FILTER(ALL('Table'),[Item1] = EARLIER('Table'[Item1)))
  VAR __table1 = FILTER(ALL('Table'),[Item2] = EARLIER('Table'[Item1))
  RETURN
    COUNTROWS(__table) + COUNTROWS (__table1)
&lt;/PRE&gt;
&lt;P&gt;Something along those lines. The above code should give you the total count of the current value of Item1 in your row for both Item1 and Item2 columns assuming I didn't miss a paren or something because I didn't test it.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2019 04:31:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-the-number-of-matching-items-in-another-column/m-p/773827#M3815</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2019-08-23T04:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of matching items in another column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-the-number-of-matching-items-in-another-column/m-p/774455#M3849</link>
      <description>&lt;P&gt;Actually, I modified the query a bit by adding the column as well.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;Column = 
  VAR __table = FILTER(ALL('Table'&lt;STRONG&gt;[Item1]&lt;/STRONG&gt;),[Item1] = EARLIER('Table'[Item1]))
  VAR __table1 = FILTER(ALL('Table'&lt;STRONG&gt;[Item2]&lt;/STRONG&gt;),[Item2] = EARLIER('Table'[Item1]))
  RETURN
    COUNTROWS(__table) + COUNTROWS (__table1)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Thanks for that, it helped!&lt;BR /&gt;Though I've got another question. Is there a way to merge the tables together and calculate a distinct count ?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2019 14:52:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-the-number-of-matching-items-in-another-column/m-p/774455#M3849</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-08-23T14:52:14Z</dc:date>
    </item>
  </channel>
</rss>

