11

I have two tables, lets call them Table1 and Table2. Table1 has a column of unique values, Table2 has a column with the same values but repeated.

What I am trying to accomplish is to calculate the number of times that value appears in Table2 as a new column in Table1.

user513951
  • 12,445
  • 7
  • 65
  • 82
Bad_Mama_Jama
  • 186
  • 2
  • 2
  • 11
  • I DAX you may not need the calculated column. Just build a measure that counts the table2 column. When that measure is applied to a pivot table or visual that groups by the unique values, you automatically get the count per unique value. – teylyn May 25 '17 at 20:38
  • Thanks teylyn, I need the value for a subsequent calc. – Bad_Mama_Jama May 25 '17 at 21:11

1 Answers1

29

If the tables are related, this is very simple:

Number of Table2 rows = COUNTROWS(RELATEDTABLE(Table2))

Here is an example:
Relationship between Table1 and Table2

Your Table2 contains multiple rows per Table1 key:
Table2

Then you can add a Calculated Column to Table1 which counts the times each item appears in Table2:
Table1 with the calculated column

If the tables are not related, you can use CALCULATE and FILTER:

Number of Table2 rows =
CALCULATE(
    COUNTROWS(Table2),
    FILTER(
        Table2,
        Table2[Column1] = Table1[Column1]
    )
)
David
  • 3,392
  • 3
  • 36
  • 47
  • I'm running into a similar issue, but I need to look for the value in the same table/column. Also the value is not quite the same. For example, I have a workflow of 1, but multiple workflows can be created based on that workflow like 1-1, 1-2, 1-3, etc. Basically I need to count how many workflows were created based on each workflow. The workflows are stored in the same table/column. Any help on how to proceed would be greatly appreciated. – viejoEngineer Aug 27 '18 at 18:35
  • @JVM, that's not enough information to give you a precise answer. Please post it as a [new question](https://stackoverflow.com/questions/ask) and include a [minimal, complete and verifiable example](https://stackoverflow.com/help/mcve). – David Aug 28 '18 at 16:13