Calculate difference between two times using Pivot Table Calculated Field

mouzzampk2014

New Member
Joined
Sep 6, 2016
Messages
24
Hi, I tried different steps two subtract two times (cell b-cell a) using calucated fieldd and output the total in cell c but my output is totally wrong. Could someone look into this for me. Much appreciated. Shall I upload sample file? Thank you
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Ab ovo...

Source = Excel.CurrentWorkbook(){[Name="[COLOR="#0000FF"]Table1[/COLOR]"]}[Content], - this is the name of your source table
yours will be probably like this:
Source = Excel.CurrentWorkbook(){[Name="Raw_Data_Pivot"]}[Content],

so try From Table then adapt the code except first line

or post the M-code here
 
Upvote 0
You are the best :) you done it. Only one thing is missing from the table is SERNO. It was there before we run this query but after I run above query SERNO gone
 
Upvote 0
you only showed a piece of what you want with changed names. It only works with your example so you have to do everything from the beginning as in the example step by step and not just copy and paste

edit:
your Pivot Table doesn't contain SERNO
so add SERNO to Group in PowerQuery and you'll see it in QueryTable and in PivotTable (I hope ;) )
I removed unnecessary columns from QueryTable to get only what I see in your result PT
but it doesn't make sense if SERNO is not used in PT
 
Last edited:
Upvote 0
This is what I have

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]// Table1
let
Source = Excel.CurrentWorkbook(){[Name="Raw_Data"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"DATE", type date}, {"SERNO", type text}, {"INITS", type text}, {"STATE", Int64.Type}, {"MAX_CPHIST_TIME", type time}, {"MIN_CPHIST_TIME", type time}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"DATE", "INITS"}, {{"Max", each List.Max([MAX_CPHIST_TIME]), type time}, {"Min", each List.Min([MIN_CPHIST_TIME]), type time}}),
#"Inserted Time Subtraction" = Table.AddColumn(#"Grouped Rows", "Subtraction", each [Max] - [Min], type duration)
in
#"Inserted Time Subtraction"

How can I add SERNO into the table so I can count number of SERNO against INITS between START AND FINISH? I can't believe you just resolved my whole issue in just few minutes
[/FONT]
 
Upvote 0
like this?

DATE(All)
INITSSum of MaxSum of MinSum of SubtractionCount of SERNO
ABH
11:02:00​
10:46:00​
0.00:16:00​
73​
BR
00:03:00​
23:32:00​
0.00:31:00​
36​
STF
16:15:00​
13:11:00​
0.03:04:00​
21​
Grand Total
03:20:00
23:29:00
0.03:51:00
130

re-download file (post #20 )
 
Last edited:
Upvote 0
How can I add SERNO into the table so I can count number of SERNO against INITS between START AND FINISH? I can't believe you just resolved my whole issue in just few minutes
[/FONT]


check steps in PQ, and more specifically Group

screenshot-74.png
 
Last edited:
Upvote 0
I done this

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]let
Source = Excel.CurrentWorkbook(){[Name="Raw_Data"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"DATE", type date}, {"SERNO", type text}, {"INITS", type text}, {"STATE", Int64.Type}, {"MAX_CPHIST_TIME", type time}, {"MIN_CPHIST_TIME", type time}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"DATE", "INITS", "SERNO"}, {{"Max", each List.Max([MAX_CPHIST_TIME]), type time}, {"Min", each List.Min([MIN_CPHIST_TIME]), type time}}),
#"Inserted Time Subtraction" = Table.AddColumn(#"Grouped Rows", "Subtraction", each [Max] - [Min], type duration)
in
#"Inserted Time Subtraction"

but after this

Subtraction results changed to

<strike>
</strike>
[/FONT]
And PivotTable show me like that which is wrong result



But your example shows exactly what I want so I am not sure what I am doing wrong
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,509
Members
449,089
Latest member
RandomExceller01

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