Forum Discussion

Mihail_D's avatar
Mihail_D
New Member
2 years ago

Power BI Count my maximum date

I have the following case, which turned out quite a difficult task. I have a table with employee number and the last date the employee was active. Additionally i have a calendar table. They have a 1:many relationship.

 

What i would like to do is create a chart where each employee is counted once for the maximum date where he was active.

 

If i have 3 people where the last actove date was 6/1/2024 on the column chart it will count 3. Each previous date when they were active should be ignored.

It should basically look like this:

 

 

 

I tried different things, the last thing i tried after some consultation was the following code:

 

 

Employee max = 
VAR __tbl = 
    FILTER(CALCULATETABLE(
    ADDCOLUMNS(
    SUMMARIZE('Table', 'Table'[PersonId], 'Calendar'[Date]), "distinct", [Employee]), 
    REMOVEFILTERS( 'Calendar'[Date], 'Calendar'[MonthnYear] )), NOT ISBLANK([distinct]))

VAR __last_date_tbl = SELECTCOLUMNS(GROUPBY(__tbl, [PersonId], "zzz", MAXX(CURRENTGROUP(), 'Calendar'[Date])), "dates", [zzz])

RETURN
IF(MAX('Calendar'[Date]) IN __last_date_tbl, 
CALCULATE([Employee]
    , Calendar[Date] = MAX('Calendar'[Date]) --__something
    ))

 

 

It generally works, if i have a single moth selected on the slicer on the page, but if i expand the selection to 2 or 3 months it couns the employee based on the last date he was active for each month. I want it to be counted on the last date for the selected period as a whole. What am i missing that makes the count by month, how can i ignore it?

 

Thank you!

 

1 Reply