Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now
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
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
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
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
Check out the October 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
110 | |
97 | |
93 | |
87 | |
68 |
User | Count |
---|---|
173 | |
134 | |
132 | |
103 | |
95 |