count distinct values in one table based on values in another table power bi

隐身守侯 提交于 2019-12-25 03:53:07

问题


I would like to do a distinct count of values on one table based on fields defined in another table, i am able to achieve this easily using SQL statements but i am unable to convert it into DAX as is used on power BI measures. Here is the SQL that i would use to count;

 SELECT COUNT (DISTINCT F.TAXPAYER_ID) 
 FROM DIM_TAXPAYER D, FACT_REGISTRATION F 
 WHERE D.TAXPAYER_ID = F.TAXPAYER_ID 
 AND D.IS_MIGRATED = 'Y' AND D.IPAGE_PROCESSED = 'Y' OR D.IS_MIGRATED = 'N';

Basically i want to count distinct taxpayer id's in the Fact_registration table that meet the criteria specified from the DIM_TAXPAYER table How can i convert this into a DAX expression?


回答1:


Assuming that you have the tables related on their ID columns, you should be able to write something like this:

Measure =
CALCULATE (
    DISTINCTCOUNT ( F[TAXPAYER_ID] ),
    FILTER (
        D,
        D[IS_MIGRATED] = "Y"
            && D[IPAGE_PROCESSED] = "Y"
            || D[IS_MIGRATED] = "N"
    )
)

The FILTER function in DAX is analogous to a WHERE clause in SQL.



来源:https://stackoverflow.com/questions/53396762/count-distinct-values-in-one-table-based-on-values-in-another-table-power-bi

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