Hi,
I'm trying to calculate the maximum usage time for our locos based on the last arrival time for the actual month and the last arrival time the month before that. The maximum time could therefore be higher or lower than the number of days in the actual month * 24 hours. The formula I use to do this is
=ROUND(CALCULATE(MAX(V_LocoKPI[ActualArrival]))-CALCULATE(MAX(V_LocoKPI[ActualArrival]);DATEADD(Dim_DatesArrival[Date];-1;MONTH));2)*24
The formula works fine for each month/loco_ID as long as the pivot table looks like below, but the aggregation of loco_ID to Loco class returns an incorrect result and if I remove loco_ID from the pivottable it will also return an incorrect result.
What I would like some help with is:
- How do I adjust the formula to show the correct total for both rows and columns (the sum of each loco_ID/month)?
- How do I adjust the formula so that it shows the correct result if I remove loco_ID and Loco class? Is it even possible to do that with DAX?
- How do I change the formula so that instead of taking the last arrival of the previous month it takes last arrival of all previous month? (it could be that there were no voyage the previous month, if so the formula should look for the latest arrival the month before that etc.)
Really appreciate any help!
Caj
[TABLE="width: 618"]
<tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Year
[/TD]
[TD]Month
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]2013
[/TD]
[TD][/TD]
[TD]Total
[/TD]
[/TR]
[TR]
[TD]Loco class
[/TD]
[TD]loco_ID
[/TD]
[TD]Values
[/TD]
[TD="align: right"]1
[/TD]
[TD="align: right"]2
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]101
[/TD]
[TD]101.001
[/TD]
[TD]MaximumTime
[/TD]
[TD="align: right"]759,84
[/TD]
[TD="align: right"]672,72
[/TD]
[TD="align: right"]672,72
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]101.002
[/TD]
[TD]MaximumTime
[/TD]
[TD="align: right"]741,84
[/TD]
[TD="align: right"]678,72
[/TD]
[TD="align: right"]678,72
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]101.003
[/TD]
[TD]MaximumTime
[/TD]
[TD="align: right"]281,52
[/TD]
[TD="align: right"]1 130,88
[/TD]
[TD="align: right"]1 130,88
[/TD]
[/TR]
[TR]
[TD]Total MaximumTime
[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]748,80
[/TD]
[TD="align: right"]672,72
[/TD]
[TD="align: right"]672,72
[/TD]
[/TR]
</tbody>[/TABLE]
I'm trying to calculate the maximum usage time for our locos based on the last arrival time for the actual month and the last arrival time the month before that. The maximum time could therefore be higher or lower than the number of days in the actual month * 24 hours. The formula I use to do this is
=ROUND(CALCULATE(MAX(V_LocoKPI[ActualArrival]))-CALCULATE(MAX(V_LocoKPI[ActualArrival]);DATEADD(Dim_DatesArrival[Date];-1;MONTH));2)*24
The formula works fine for each month/loco_ID as long as the pivot table looks like below, but the aggregation of loco_ID to Loco class returns an incorrect result and if I remove loco_ID from the pivottable it will also return an incorrect result.
What I would like some help with is:
- How do I adjust the formula to show the correct total for both rows and columns (the sum of each loco_ID/month)?
- How do I adjust the formula so that it shows the correct result if I remove loco_ID and Loco class? Is it even possible to do that with DAX?
- How do I change the formula so that instead of taking the last arrival of the previous month it takes last arrival of all previous month? (it could be that there were no voyage the previous month, if so the formula should look for the latest arrival the month before that etc.)
Really appreciate any help!
Caj
[TABLE="width: 618"]
<tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Year
[/TD]
[TD]Month
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]2013
[/TD]
[TD][/TD]
[TD]Total
[/TD]
[/TR]
[TR]
[TD]Loco class
[/TD]
[TD]loco_ID
[/TD]
[TD]Values
[/TD]
[TD="align: right"]1
[/TD]
[TD="align: right"]2
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]101
[/TD]
[TD]101.001
[/TD]
[TD]MaximumTime
[/TD]
[TD="align: right"]759,84
[/TD]
[TD="align: right"]672,72
[/TD]
[TD="align: right"]672,72
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]101.002
[/TD]
[TD]MaximumTime
[/TD]
[TD="align: right"]741,84
[/TD]
[TD="align: right"]678,72
[/TD]
[TD="align: right"]678,72
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]101.003
[/TD]
[TD]MaximumTime
[/TD]
[TD="align: right"]281,52
[/TD]
[TD="align: right"]1 130,88
[/TD]
[TD="align: right"]1 130,88
[/TD]
[/TR]
[TR]
[TD]Total MaximumTime
[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]748,80
[/TD]
[TD="align: right"]672,72
[/TD]
[TD="align: right"]672,72
[/TD]
[/TR]
</tbody>[/TABLE]
Last edited: