cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Kevin_Gitonga Helper I
Helper I

DINSTINCT COUNT OF VALUES IN ONE TABLE BASED ON VALUES IN ANOTHER COLUMN

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 ACCEPTED SOLUTION

Accepted Solutions
v-piga-msft Resident Rockstar
Resident Rockstar

Re: DINSTINCT COUNT OF VALUES IN ONE TABLE BASED ON VALUES IN ANOTHER COLUMN

Hi @Kevin_Gitonga,

 

Assuming that you have two tables like below and there is a relationship between the two tables.

 

tables.png

 

Then you could create the measure refer to the formula below.

 

distinct_cout =
CALCULATE (
    DISTINCTCOUNT ( 'Table F'[ID] ),
    FILTER (
        'Table D',
        'Table D'[ID] = RELATED ( 'Table F'[ID] )
            && 'Table D'[IS_MIGRATED] = "Y"
            && 'Table D'[IPAGE_PROCESSED] = "Y"
    )
)

Here is the output.

 

output.PNG

 

In Power BI, "&&"means ''And'' and "||" means "OR". You also could use AND and OR functions in dax.

 

If you still need help, please share some data sample and your desired output so that we could help further on it.

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Highlighted
affan Solution Sage
Solution Sage

Re: DINSTINCT COUNT OF VALUES IN ONE TABLE BASED ON VALUES IN ANOTHER COLUMN

Hi @Kevin_Gitonga

 

 

If you share some sample data that will help reaching the solution

 

Regards 

Affan

v-piga-msft Resident Rockstar
Resident Rockstar

Re: DINSTINCT COUNT OF VALUES IN ONE TABLE BASED ON VALUES IN ANOTHER COLUMN

Hi @Kevin_Gitonga,

 

Assuming that you have two tables like below and there is a relationship between the two tables.

 

tables.png

 

Then you could create the measure refer to the formula below.

 

distinct_cout =
CALCULATE (
    DISTINCTCOUNT ( 'Table F'[ID] ),
    FILTER (
        'Table D',
        'Table D'[ID] = RELATED ( 'Table F'[ID] )
            && 'Table D'[IS_MIGRATED] = "Y"
            && 'Table D'[IPAGE_PROCESSED] = "Y"
    )
)

Here is the output.

 

output.PNG

 

In Power BI, "&&"means ''And'' and "||" means "OR". You also could use AND and OR functions in dax.

 

If you still need help, please share some data sample and your desired output so that we could help further on it.

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
‘Better Together’ T-Shirt Contest – Winner Announced!

‘Better Together’ T-Shirt Contest – Winner Announced!

And the winner is...

Announcing the New Spanish Forum

Announcing the New Spanish Forum

Do you need help in Spanish? Check out our new Spanish community section.

April 2020 Community Highlights

April 2020 Community Highlights

Info on our Super Users, MBAS content and badges, and updates to our support articles. - Read the full Community Highlights.

MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

Top Solution Authors
Top Kudoed Authors