简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM