12

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.

2
  • 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. Commented May 25, 2017 at 20:38
  • Thanks teylyn, I need the value for a subsequent calc. Commented May 25, 2017 at 21:11

1 Answer 1

31

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]
    )
)
Sign up to request clarification or add additional context in comments.

2 Comments

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.
@JVM, that's not enough information to give you a precise answer. Please post it as a new question and include a minimal, complete and verifiable example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.