PowerPivot - calculation issue with duplicate data and count of data

vidurp

New Member
Joined
May 22, 2013
Messages
1
Hello,

I am trying to calculate the difference in time between the current movement type and the last movement made by a particular vehicle according to the following data set in PowerPivot.

For instance, for Truck A I would like to calculate the time difference between movement 2 and 1 that occured on 3/11/2013 and 3/7/2013 respectively. I have developed the following DAX formula to current row with the transaction date of the next row, which I can then use to do a simple subtraction DAX formula to calculate time difference:

=IF(CALCULATE(MAX([TransactionDate]), FILTER(ALL('Data'), 'Data'[Vehicle]=EARLIER('Data'[Vehicle])), FILTER(ALL('Data'), 'Data'[LastMovementType]=EARLIER('Data'[MovementType])))<[TransactionDate],
BLANK(),
CALCULATE(MAX([TransactionDate]), FILTER(ALL('Data'), 'Data'[Vehicle]=EARLIER('Data'[Vehicle])), FILTER(ALL('Data'), 'Data'[LastMovementType]=EARLIER('Data'[MovementType]))))


The issue with the formula is that it doesn't allow me to use the VALUE/VALUES function instead of the MIN/MAX to populate the date. Instead, the MIN/MAX functions only pick the earliest or latest date that a MovementType occured on. When there are repetitions in LastMovementType, it picks the maximum date for the occurence of the particular LastMovementType. For instance, for Truck D's data on 1/31/2013, applying the above formula produces 4/23/2013 when I want it to produce 3/8/2013 which is the next day of the next movement. It produces 4/23/2013 because that is the maximum date where the LastMovementType is a 4.

I assume one method to solve this is by counting the number of repetitions of LastMovementType and ranking the number of duplicates to spit out the first repetition, or the second, or the third and so on. This would require a COUNT formula nested with an EARLIER function +1 (to continue down a rank).

Although this would work perfectly in VBA in a loop, I require some guidance on how to do this in a simpler way in PowerPivot. I would GREATLY appreciate any help you could provide as this has taken me a TON of time to solve up to this point. Any suggestions on optimizations would be appreciated!

Thanks!

-Vidur
Vehicle
TransactionDate
MovementType
LastMovementType
Truck A
3/7/2013
1
4
Truck A
3/11/2013
2
1
Truck A
3/13/2013
3
2
Truck A
3/19/2013
4
3
Truck B
1/8/2013
4
3
Truck B
2/14/2013
1
4
Truck B
3/4/2013
42
1
Truck B
3/27/2013
3
42
Truck B
4/16/2013
5
3
Truck B
4/16/2013
1
5
Truck C
4/18/2013
1
4
Truck C
4/30/2013
2
1
Truck C
1/3/2013
1
4
Truck C
1/7/2013
2
1
Truck D
1/8/2013
43
4
Truck D
1/31/2013
4
43
Truck D
3/8/2013
1
4
Truck D
3/12/2013
2
1
Truck D
3/20/2013
3
2
Truck D
3/21/2013
4
3
Truck D
4/23/2013
1
4
Truck D
4/25/2013
2
1

<TBODY>
</TBODY>
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,214,376
Messages
6,119,181
Members
448,871
Latest member
hengshankouniuniu

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