Forum Discussion
Sum up the difference in Maximum and minimum value per meter group
Please assist me with a measure to calculate the total hours in the below table using the logic below. i used the dax below , but my subtotal in the table is not summing up.
SMU Hrs = IFERROR( CALCULATE(MAX(EngineReading[StopReading])-MIN(EngineReading[StartReading]),EngineReading[MeterID]="HRS")+CALCULATE(MAX(EngineReading[StopReading])-MIN(EngineReading[StartReading]),EngineReading[MeterID]="HRS1"),0)
Total Hours = Difference between Maximum end reading and minimum start reading when meter is HRS ,Difference between Maximum end reading and minimum start reading when meter is HRS1.
| Shift Type | Shift Date | Equip ID | Meter | Start Hours | End Reading | Difference |
| Day Shift | 22-10-2019 | DR770 | HRS1 | 152.50 | 156.80 | 4.30 |
| Night Shift | 22-10-2019 | DR770 | HRS1 | 157.00 | 161.60 | 4.60 |
| Day Shift | 23-10-2019 | DR770 | HRS1 | 161.70 | 167.10 | 5.40 |
| Night Shift | 23-10-2019 | DR770 | HRS1 | 167.10 | 172.40 | 5.30 |
| Day Shift | 24-10-2019 | DR770 | HRS1 | 172.40 | 178.70 | 6.30 |
| Night Shift | 24-10-2019 | DR770 | HRS1 | 178.70 | 184.20 | 5.50 |
| Day Shift | 25-10-2019 | DR770 | HRS1 | 184.30 | 189.10 | 4.80 |
| Day Shift | 28-10-2019 | DR770 | HRS1 | 189.50 | 193.10 | 3.60 |
| Night Shift | 28-10-2019 | DR770 | HRS1 | 193.10 | 197.70 | 4.60 |
| Day Shift | 29-10-2019 | DR770 | HRS1 | 197.70 | 202.20 | 4.50 |
| Night Shift | 29-10-2019 | DR770 | HRS1 | 202.20 | 208.10 | 5.90 |
| Day Shift | 30-10-2019 | DR770 | HRS1 | 208.20 | 218.20 | 10.00 |
| Night Shift | 30-10-2019 | DR770 | HRS1 | 218.20 | 228.70 | 10.50 |
| Day Shift | 31-10-2019 | DR770 | HRS1 | 228.80 | 232.00 | 3.20 |
| Night Shift | 6-10-2019 | DR770 | HRS | 2319.10 | 2321.60 | 2.50 |
| Day Shift | 7-10-2019 | DR770 | HRS | 2321.60 | 2330.80 | 9.20 |
| Night Shift | 7-10-2019 | DR770 | HRS | 2330.80 | 2338.00 | 7.20 |
| Day Shift | 8-10-2019 | DR770 | HRS | 2338.00 | 2341.20 | 3.20 |
| Day Shift | 9-10-2019 | DR770 | HRS | 2341.20 | 2345.70 | 4.50 |
| Night Shift | 9-10-2019 | DR770 | HRS | 2345.70 | 2349.70 | 4.00 |
| Day Shift | 10-10-2019 | DR770 | HRS | 2349.70 | 2353.40 | 3.70 |
| Day Shift | 11-10-2019 | DR770 | HRS | 2353.40 | 2359.10 | 5.70 |
| Night Shift | 11-10-2019 | DR770 | HRS | 2359.10 | 2364.60 | 5.50 |
| Night Shift | 12-10-2019 | DR770 | HRS | 2364.60 | 2370.60 | 6.00 |
| Day Shift | 13-10-2019 | DR770 | HRS | 2370.60 | 2379.90 | 9.30 |
| Night Shift | 13-10-2019 | DR770 | HRS | 2379.90 | 2389.50 | 9.60 |
| Day Shift | 14-10-2019 | DR770 | HRS | 2389.50 | 2396.40 | 6.90 |
| Night Shift | 14-10-2019 | DR770 | HRS | 2396.40 | 2401.20 | 4.80 |
| Day Shift | 15-10-2019 | DR770 | HRS | 2401.20 | 2409.00 | 7.80 |
| Night Shift | 15-10-2019 | DR770 | HRS | 2409.00 | 2418.90 | 9.90 |
| Day Shift | 16-10-2019 | DR770 | HRS | 2418.90 | 2428.40 | 9.50 |
| Night Shift | 16-10-2019 | DR770 | HRS | 2428.40 | 2437.40 | 9.00 |
| Day Shift | 17-10-2019 | DR770 | HRS | 2437.40 | 2444.00 | 6.60 |
| Night Shift | 17-10-2019 | DR770 | HRS | 2444.00 | 2446.60 | 2.60 |
| Night Shift | 18-10-2019 | DR770 | HRS | 2446.60 | 2455.10 | 8.50 |
| Day Shift | 21-10-2019 | DR770 | HRS | 2455.10 | 2460.90 | 5.80 |
| Night Shift | 21-10-2019 | DR770 | HRS | 2460.90 | 2464.00 | 3.10 |
11 Replies
- Pragati11
Super User
Hi Anonymous ,
You can achieve this as follows:
1. Create 2 measures. One for maximum End Reading, one for minimum Start Reading.
Max End Reading = MAX([End Reading])
Min Start Reading = MIN([Start Reading])
2. Add a calculation as follows for Total Hours:
Total Hours = IF([Meter] = "HRS" || [Meter] = "HRS1", [Max End Reading] - [Min Start Reading], 0)
Let me know if this works.
Thanks.
- AnonymousNot applicable
Hi Pragati11,
Thanks for the reply
1. Ist measure creatly successfuly,
2. 2nd Measure is not working, as i am unable to select [Meter] when i use IF.
Thanks
- AnonymousNot applicable
If you want column then use below dax.
Diff=IF(table[Meter] in {"HRS","HRS1"},Table[Endtime]-Table[StartTime],0)
If you want measure
Diff=Diff=IF(Min(table[Meter]) in {"HRS","HRS1"},min(Table[Endtime])-min(Table[StartTime]),0)
Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar
If I resolve your problem Mark it as a solution and give kudos.