218
Views
5
Comments
Solved
Count of distinct records in an aggregate.

Hey guys! 


Once again I come to ask you for help with a situation in my project. 

I need to count distinct records in my aggregate. 


The result I'm trying to get is how many distinct users I have in my CreatedBy column so I can use the result of that count in an expression on my screen. 

Thank you very much to anyone who can help! 

Thank you very much 

2019-01-07 16-04-16
Siya
 
MVP
Solution

You can execute a SQL statement like 

SELECT COUNT(DISTINCT columnName) FROM tableName WHERE condition; 

This will perform better and there is reduced data transfer in this particular scenario.

2022-07-11 14-05-36
Jeroen Barnhoorn
Solution

Hi Luiz,

Using a 'Group By' on your CreatedBy column in the aggregate (and then taking the length of the resulting list) should give you just that.

(Right click on the column and then select 'Group By')

2025-06-01 02-51-51
YASH PAL
Solution

Hi @Luiz Lima 

just group by the column that has unique values and then aggregate count it self give you that value.

2022-07-11 14-05-36
Jeroen Barnhoorn
Solution

Hi Luiz,

Using a 'Group By' on your CreatedBy column in the aggregate (and then taking the length of the resulting list) should give you just that.

(Right click on the column and then select 'Group By')

2019-01-07 16-04-16
Siya
 
MVP
Solution

You can execute a SQL statement like 

SELECT COUNT(DISTINCT columnName) FROM tableName WHERE condition; 

This will perform better and there is reduced data transfer in this particular scenario.

2025-06-01 02-51-51
YASH PAL
Solution

Hi @Luiz Lima 

just group by the column that has unique values and then aggregate count it self give you that value.

2023-10-12 01-08-03
Luiz Lima

Thank you very much to everyone who helped, all the solutions were valid!

Thank you very much.

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Although all replies marked as solution give you the desired result, only the reply with the SELECT DISTINCT is the best reply, as it wil perform way better then the group by solution with using an aggregate.

Always keep in mind performance.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.