- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Help with DAX Average of Distinct Count
Hello,
I don't know what I'm doing wrong.
What I'm trying to do is have the salary value (at the time of admission) for each person that was admitted in (example) January 2021.
https://dropmefiles.com/8VYKy This is the file I'm using.
These are the connections made. The other connections between dCalendario and Colaboradores is only between dates (All dates are linked).
Teste =
CALCULATE(
LASTNONBLANKVALUE(Colaboradores[mesref], AVERAGE(Colaboradores[valsal])),
USERELATIONSHIP(Colaboradores[mesref], dCalendario[Data]),
VALUES(Colaboradores[Chave])
)
Admissões =
DISTINCTCOUNT(Colaboradores[Chave])
This is the table I'm trying to get right, but the Average on Teste does not match.
Trying out I found out that some Chave (Key) are multiplying the salary value, 2, 3, 4 times. The top 3 rows should be 3.118,17 on Teste 4.
Teste 4 =
CALCULATE(
LASTNONBLANKVALUE(Colaboradores[mesref], SUM(Colaboradores[valsal])),
USERELATIONSHIP(Colaboradores[mesref], dCalendario[Data]),
VALUES(Colaboradores[Chave])
)
This is the same measure as Teste, but with sum instead of average.
Thanks,
Diego
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi @floressdiego ,
Which table the field [Admissoes] is from? Is it a fact field in the table or measure? If it is a measure, please provide the related formula. If the field [Admissoes] is from another table except the table Colaboradores, please provide some raw data in that table and relationship info with the table Colaboradores. Also please provide the calculation logic of average values with some special examples. Thank you.
Best Regards
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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

Helpful resources
Join us at the Microsoft Fabric Community Conference
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Power BI Monthly Update - February 2025
Check out the February 2025 Power BI update to learn about new features.

Subject | Author | Posted | |
---|---|---|---|
10-09-2024 09:44 AM | |||
08-13-2024 09:40 AM | |||
04-22-2024 02:59 PM | |||
06-22-2023 05:25 AM | |||
10-07-2024 10:50 AM |
User | Count |
---|---|
87 | |
81 | |
53 | |
38 | |
35 |