Power BI, DAX--How do I count rows in one table based on values in another table?

只愿长相守 提交于 2019-12-10 17:48:30

问题


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.


回答1:


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]
    )
)


来源:https://stackoverflow.com/questions/44187150/power-bi-dax-how-do-i-count-rows-in-one-table-based-on-values-in-another-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!