cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
floressdiego
Helper I
Helper I

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.

 

floressdiego_0-1661342810619.png

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])
 
floressdiego_1-1661343600332.png

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.

floressdiego_2-1661343790568.png

 

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

 

4 REPLIES 4
yingyinr
Community Support
Community Support

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.

yingyinr_1-1661764467668.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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:

 

Chavevalsalmesref
1231000,0001/01/2021
1231000,0001/01/2021
1231000,0001/01/2021
13000,0001/01/2021
24000,0001/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 )

yingyinr_0-1662098319388.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.

 

floressdiego_1-1662119939021.png

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

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

BizApps LATAM 2023

Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

Power Platform Bootcamp

Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.