Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

How to get the latest event before a specific date? Count with filtering

Hi,

I have data as below. What I am trying to achievie is to calculate headcount on a particular positions, using a chosen date (independent from the table).

 

 

DepWorkerEventPositionEvent_orderDate
ITAdamHireJunior101/01/2020
ITAdamPromotionSenior201/06/2021
ITAdamPromotionExpert301/09/2022
ITAdamPromotionManager 1401/10/2023
HRBenHireExpert101/03/2020
HRBenPromotionManager 1201/08/2022
HRBenPromotionManager 2301/12/2023

 

Assuming I set the date filter to 31-08-2022 I would like to get the results as following:

(pivot table, where Rows = Department, Columns = Position, value = count of employees on a particular position at the selected date)

DepJuniorSeniorExpertManager 1 Manager 2
IT 1   
HR   1 

I tried to do COUNT with FILTER on date, but I couldn't manage to get only the latest position. 

calculate(count(table[Worker]), FILTER(table, table[Date]<=_min))
The calculation above returns 1 also for each previous positions (so for Adam: Junior and Senior, for Ben Senior, Expert and Manager).

any ideas?

4 REPLIES 4
Anonymous
Not applicable

Hi @Anonymous ,

Please try like:

Measure = 
VAR _max_date =
    CALCULATE ( MAX ( 'Calendar'[Date] ), ALLSELECTED () )
VAR _max_order =
    CALCULATE ( MAX ( 'Table'[Event_order] ), ALL ( 'Table'[Position] ) )
VAR _position =
    CALCULATE ( MAX ( 'Table'[Position] ), 'Table'[Event_order] = _max_order )
VAR _result = SUMX('Table',IF('Table'[Position]=_position && 'Table'[Event_order] =_max_order,1))
RETURN
    _result

vcgaomsft_0-1698304864601.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Anonymous
Not applicable

Hi, @Anonymous . It doesn't work on my side.

Still getting "1" at the top event (regardless the date).

Edit: I think I know what you did, but the date filter can't be filtering my data. It should be an independent date to choose.

gregx_0-1699545385530.png

 

VahidDM
Super User
Super User

Hey @Anonymous 

 

What expression have hou used for _min?

 

can you share the full codes,

 

Appreciate your Kudos!! 

LinkedIn | Twitter | Blog | YouTube 

Anonymous
Not applicable

hi @VahidDM 

var _min = minx(allselected(GenTableDates),GenTableDates[GDate])
it comes from a table with generated dates, but it doesn't really matter

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors