Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
lailarhc
Creator
Creator

Using distinct with Sum in set analysis

Hello.
I need to know the sum of Hours (horas) of the distinct values of a dimension (Curso).
Here's what my expression for the KPI looks like:
=Sum({$ <Curso =- {''}>} Horas)

I thought I could use =Sum({$ <distinct Curso =- {''}>} Horas), but that's not allowed.

In the following image, the Kpi should display 44 instead of 88, as 2 + 10 + 16 + 8 + 8 = 44.

08.png

Here's another example:
09.png
It should display 181 as that is the result of 25 + 24 + 60 + 24 + 40 + 8


What am I doing wrong?
Thank you in advance.

1 Solution

Accepted Solutions
sunny_talwar

Try this

Sum(Aggr(
    Sum(DISTINCT {$<Curso =- {''}>} Horas),
Curso, Servidor, Ano))

View solution in original post

4 Replies
sunny_talwar

Try this

 

Sum(Aggr(
    Sum(DISTINCT {$<Curso =- {''}>} Horas),
Curso))

 

lailarhc
Creator
Creator
Author

I thought it worked as the kpi was displaying the correct numbers, until I came across this:
10.png
I filtered it by year. It's the same course taken by four different employees. It should count as 8 * 4 hours, but it's only counting the course once.

Why is that?

And thank you for answering 🙂

sunny_talwar

Try this

Sum(Aggr(
    Sum(DISTINCT {$<Curso =- {''}>} Horas),
Curso, Servidor, Ano))
lailarhc
Creator
Creator
Author

It worked!
Thank you 🙂