Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
ssbagley
Helper III
Helper III

Distinct Count (Direct Query) - Why is this so hard!?

Hi - me again.  Source data is employee expense submissions in a SQL table via Direct Query.  I want to count the number of expense reports by employee for a given date range (slicer).  I've tried:

= Countrows(Summarize(Expenses, Expenses[ReportNumber]) )

= DISTINCTCOUNT (Expenses[ReportNumber] )

= COUNTROWS(DISTINCT(SELECTCOLUMNS(FILTER(Expenses,Expenses[ReportNumber]<>0),"Reports",Expenses[ReportNumber])))

 

I know this has to be possible -- what am I doing wrong??

7 REPLIES 7
PVO3
Impactful Individual
Impactful Individual

Im sorry. Instead of primairy key i meant your name column. But im afraid this operation over this column has performance issues

I don't want to countrows of the name column though because one name may have 500 unique expense reports.  I want to identify the number of expense reports per person (not number of expense submissions). 

PVO3
Impactful Individual
Impactful Individual

So then do COUNTROWS(ALL(Expenses[ReportNumber]))

That doesn't work, but I figured it out anyway.  Thanks!

usually you publish how you solved it

PVO3
Impactful Individual
Impactful Individual

COUNTROWS(ALL('Table'[Primairy key])) is working fine for me

This displayed the same value for every employee which is not correct, but it did return a result which is an improvement from my previous attempts!

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors