Forum Discussion
Count staff that move between roles
- 4 years ago
Hi jmilne320
I hope this is what you're looking forActive Staff = CALCULATE ( COUNTROWS ( FILTER ( CALCULATETABLE ( Pilots, CROSSFILTER ( Pilots[Staff Number], events[Staff Number], BOTH ) ), MAXX ( RELATEDTABLE ( Events ), Events[Date] ) <= MAX ( 'Date'[Date] ) ) ), 'Date'[date] <= MAX ('Date'[date] ) ) - 4 years ago
Hi jmilne320
First you need to create a new column for end date in the vents table:end date = MINX ( FILTER ( CALCULATETABLE ( Events, ALLEXCEPT ( Events, Events[Staff Number] ) ), Events[start date] > EARLIER ( Events[start date] ) ), Events[start date] )Then you need to deactivate or delete the relationship with the date table
The following would be the measure
Active Staff = VAR CurrentDate = MAX ( 'Date'[date] ) RETURN COUNTROWS ( FILTER ( Events, VAR StartDate = Events[start date] VAR EndtDate = COALESCE ( Events[End date], DATE ( 3000, 1, 1 ) ) RETURN StartDate <= CurrentDate && EndtDate >= CurrentDate ) )
Hi jmilne320
I hope this is what you're looking for
Active Staff =
CALCULATE (
COUNTROWS (
FILTER (
CALCULATETABLE (
Pilots,
CROSSFILTER ( Pilots[Staff Number], events[Staff Number], BOTH )
),
MAXX ( RELATEDTABLE ( Events ), Events[Date] ) <= MAX ( 'Date'[Date] )
)
),
'Date'[date] <= MAX ('Date'[date] )
)- jmilne3204 years agoFrequent Visitor
That's incredible tamerj1, thank you so much! I never would have been able to come to that solution by myself.
I've marked this as the solution to my inital question, but seeing as you've been so helpful I do have one further question. Is there a way to decrease the count of a posting as a staff member moves to another posting? Ie in the example above in the period 22R07 there is 1 A320 Captain CTL and 1 A320 Captain Office who should then decrease to 0 in 22R08 as they both become F100 Captain Office.
Kind reagrds,
James
- tamerj14 years ago
Community Champion
Hi jmilne320
First you need to create a new column for end date in the vents table:end date = MINX ( FILTER ( CALCULATETABLE ( Events, ALLEXCEPT ( Events, Events[Staff Number] ) ), Events[start date] > EARLIER ( Events[start date] ) ), Events[start date] )Then you need to deactivate or delete the relationship with the date table
The following would be the measure
Active Staff = VAR CurrentDate = MAX ( 'Date'[date] ) RETURN COUNTROWS ( FILTER ( Events, VAR StartDate = Events[start date] VAR EndtDate = COALESCE ( Events[End date], DATE ( 3000, 1, 1 ) ) RETURN StartDate <= CurrentDate && EndtDate >= CurrentDate ) )- jmilne3204 years agoFrequent Visitor
Ahhhhh I can't begin to explain how excited I am! This is exactly what I have been trying to achieve for weeks, I'm very thankful for your help. It is very interesting to see how you went about troubleshooting my problem and the formulas you employed along the way. I'm looking forward to further exploring Power BI!
Kind regards,
James