Counting State changes

masterelaichi

New Member
Joined
Sep 29, 2014
Messages
49
Hi,

I am not sure what the rules are about cross-posting. I have also posted this same query in ExceleratorBI. Apologies in advance if cross-posting isn't allowed

I have a table containing staff data. A certain staff member can, over time, change different position ( Position column in the data set)

I am trying to count how may times the position changes, i,e, If employee 1 is initially in Position A and then moves to B, that should count as 1. If, the next position remains at B, then no change. Basically, I am trying to include a code that flags a change in the position which can be counted

I am trying count the movement of an employee by position by month

How do I attach an excel file with a sample dataset ?

Thank you
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I think I have made some progress. I created an index column for the table and used variables and the Lookupvalue function. I created a new column called ChangeFlag which indicates when there is a change in the position

The flag conditions are as follows -
1. Same employee number, different position - flag is set to "Changed"
2. Different employee number, different or same position - flag is set to "No change"

ChangeFlag =

VAR currentPosition= LOOKUPVALUE(PersonPositionTable[Position],PersonPositionTable[Index],PersonPositionTable[Index],PersonPositionTable[Position])
VAR previousPosition = LOOKUPVALUE(PersonPositionTable[Position],PersonPositionTable[Index],PersonPositionTable[Index]-1,PersonPositionTable[Position])
VAR currentPersonnel = LOOKUPVALUE(PersonPositionTable[Emp number],PersonPositionTable[Index],PersonPositionTable[Index],PersonPositionTable[Emp number])
VAR previousPersonnel = LOOKUPVALUE(PersonPositionTable[Emp number],PersonPositionTable[Index],PersonPositionTable[Index]-1,PersonPositionTable[Emp number])
VAR flagPositionChange = if(or(currentPosition=previousPosition,currentPersonnel<>previousPersonnel),"No Change","Changed")

Return
flagPositionChange

I haven't found an anomaly as yet but I am still running some tests. If there is a simpler way to tackle this, I would love to know it :D
 
Upvote 0

Forum statistics

Threads
1,223,723
Messages
6,174,108
Members
452,544
Latest member
aush

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top