count distinct by two columns sql code example

Example 1: pandas groupby column count distinct values

# Pandas group by a column looking at the count unique/count distinct values of another column

df.groupby('param')['group'].nunique()

Example 2: dax count distinct based on 2 columns

--Without filters
Measure1 = COUNTROWS(GROUPBY(User,User[FNAME],User[Card ID],User[Health ID],User[Gender]))
--With filters
Measure2 = COUNTROWS(FILTER(GROUPBY(User,User[FNAME],User[Card ID],User[Health ID],User[Gender]),User[Gender]="M"))