问题
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