Forum Discussion
Help with DAX Average of Distinct Count
Hello,
I think I forgot this one.
DISTINCTCOUNT(Colaboradores[Chave])
Right now it is just a distinct count.
What I want is the average of 'Colaboradores[valsal]' but only once per key, I don't wanna count the same key multiple times. It's like getting the average salary per month, but right now it's counting people multiple times and setting the average lower or higher than expected.
Ex:
| Chave | valsal | mesref |
| 123 | 1000,00 | 01/01/2021 |
| 123 | 1000,00 | 01/01/2021 |
| 123 | 1000,00 | 01/01/2021 |
| 1 | 3000,00 | 01/01/2021 |
| 2 | 4000,00 | 01/01/2021 |
I expect the average of 1000,00 + 3000,00 + 4000,00, being 8000 / 3 = 2666,67
And not (1000 + 1000 + 1000 + 3000 + 4000) / 5 = 2000,00
Thanks for any help
Hi floressdiego ,
You can create a measure as below to get it:
Average =
VAR _count =
DISTINCTCOUNT ( 'Colaboradores'[Chave] )
VAR _tab =
SUMMARIZE (
'Colaboradores',
'Colaboradores'[Chave],
"@maxvalsal", MAX ( 'Colaboradores'[valsal] )
)
RETURN
DIVIDE ( SUMX ( _tab, [@maxvalsal] ), _count )
Best Regards
- floressdiego4 years ago
Helper I
Thanks for the reply.
It worked with filtering the date and with Chave as a Column/Row. If I put another column from the table it doesn't really do.
All I did below was adding codcar, a column from the table (role code), and Chave as rows in a matrix with the columns Average and Admissões.
Chave 584/1/401 is counting twice in Average, but it is not entering the total value, the total is correct. It shouldn't appear below codcar 10/401.
After thinking about it, I don't know if it makes it more clear, I don't know if I need to make another post because maybe it will change the topic slightly, but I think the thought behind this is: I select a month (01/2021), I need the last datalt (date) before or equal the selected date, I need the last altccu ( alteration of center cost, date also) and then I will take the average of valsal (salary) for every Chave I got. (they are all in the same table)
I think this changes a bit, since this is more of some math with the last of each date I got rather than average of a distinct count.
If I need to create another topic, let me know and I will do so...
Thanks