Power BI,DAX —如何根据另一个表中的值对一个表中的行进行计数? [英] Power BI, DAX--How do I count rows in one table based on values in another table?
问题描述
我有两个表,我们称它们为Table1和Table2。表1具有一列唯一值,表2具有相同值但重复的列。
我要完成的工作是计算该值出现的次数在表2中作为表1中的新列。
如果表相关,这很简单:
Table2行数= COUNTROWS(RELATEDTABLE(Table2))
以下是示例:
然后,您可以将计算列添加到Table1中,以计算表2中每个项目出现的时间:
如果表不相关,则可以使用 CALCULATE
和 FILTER
:
Table2行数=
CALCULATE(
COUNTROWS(Table2),
FILTER(
Table2,
Table2 [Column1] = Table1 [Column1]
)
)
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.
If the tables are related, this is very simple:
Number of Table2 rows = COUNTROWS(RELATEDTABLE(Table2))
Here is an example:
Your Table2 contains multiple rows per Table1 key:
Then you can add a Calculated Column to Table1 which counts the times each item appears in Table2:
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]
)
)
这篇关于Power BI,DAX —如何根据另一个表中的值对一个表中的行进行计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!