Calculating Time Between Dates in a Pivot Table

jabu

New Member
Joined
Jul 26, 2022
Messages
5
Office Version
  1. 2019
Platform
  1. Windows
Hello

I am trying to calculate and then chart the difference between dates in a pivot table and I could use some help.

I have a list of dated transactions for various customers and I am trying to find the time elapsed since the previous payment so that I can show it in a stacked column chart. There could be any number of payments for a given customer and multiple payments could be received on the same day. Also each payment is labeled ("#1", "#2", "Deposit", "Prepayment", etc) and I'd like those labels to be reflected in the legend of the chart.

I am trying to do this with pivot tables because I am working with imported Quickbooks data. I want to be able to paste a huge list of transactions from QB that has all the info I need, then simply click refresh on my pivot tables and everything updates. I already have a bunch of other pivot tables and charts I've put together that work like this without me needing to clean/process the data in any way.

I'm sure I need to use Values with Show Values As "Difference From" but I cannot figure out how to get it to work. The values in the table always end up as either N/A, 1, or the date itself. I've tried tons of variations of different Base Fields and Base Items and I can't figure it out.

For example, if Customer A payment #1 received 1/1/21, payment #2 received 1/11/21, then payment #3 received 1/26/21, then there would be a stacked column chart with a column for Customer A and that column would have two segments, one of value 10 (labeled "payment #2") and the next of value 15 (labeled "payment #3").

Does that make sense? Ultimately I'm trying to get a visualization showing: this is how long each customer/project took and this is how long it was between payments for each customer.


Here are some example transactions:

DateCustomerMemoAmount
3/9/2021Customer CDraw #526339
4/14/2021Customer JDraw #121447
4/23/2021Customer DDraw #110263
5/18/2021Customer HDraw #516948
5/24/2021Customer JDraw #228596
6/21/2021Customer DDraw #213684
6/21/2021Customer JDraw #328596
6/23/2021Customer HDraw #611299
8/25/2021Customer DDraw #313684
9/9/2021Customer JDraw #428596
10/12/2021Customer DDraw #413684


Here is what my pivot table currently looks like:

income and expenses TEST.xlsx
ABCDEFGH
3Sum of DateColumn Labels
4Row LabelsDraw #1Draw #2Draw #3Draw #4Draw #5Draw #6Grand Total
5Customer A10/14/202111/23/20211/25/20222/28/20224/1/20224/8/20226/13/2632
6Customer B3/3/20224/14/20225/19/20226/22/20227/25/202211/21/2511
7Customer C3/9/20213/9/2021
8Customer D4/23/20216/21/20218/25/202110/12/202111/16/20211/14/20222/23/2630
9Customer E10/22/202111/15/20212/1/20223/8/20225/13/20225/13/20229/13/2632
10Customer F3/21/20224/14/20225/24/20227/1/20225/29/2389
11Customer G12/8/20213/12/20223/31/20225/11/20227/18/20227/18/202211/5/2633
12Customer H5/18/20216/23/202111/10/2142
13Customer I12/28/20212/4/20222/28/20224/20/20225/22/20227/1/20226/16/2633
14Customer J4/14/20215/24/20216/21/20219/9/202111/16/202112/30/20219/26/2629
15Customer K7/1/20227/1/2022
16Grand Total1/13/29977/10/28756/26/28766/22/28776/17/29983/19/27553/19/7880
Sheet1


Fields:

1658874980120.png


Which creates a stacked column chart that is almost what I want except that the vertical axis should be # of days not raw date.

1658874998701.png


Any help would be greatly appreciated.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi,

Take a look if this is what you're looking for.
LOOKUP Salary By Year.xlsm
ABCDEFGHIJKLMNOPQ
1DateCustomerMemoAmountDelta DaysSum of Delta DaysColumn Labels
29-3-2021Customer CDraw #526339-Row LabelsDraw #1Draw #2Draw #3Draw #4Draw #5Draw #6Grand Total
314-4-2021Customer JDraw #121447-Customer C00
423-4-2021Customer DDraw #110263-9-mrt00
518-5-2021Customer HDraw #516948-Customer D0596548172
624-5-2021Customer JDraw #22859640,0023-apr00
721-6-2021Customer DDraw #21368459,0021-jun5959
821-6-2021Customer JDraw #32859628,0025-aug6565
923-6-2021Customer HDraw #61129936,0012-okt4848
1025-8-2021Customer DDraw #31368465,00Customer H03636
119-9-2021Customer JDraw #42859680,0018-mei00
1212-10-2021Customer DDraw #41368448,0023-jun3636
13Customer J0402880148
1414-apr00
1524-mei4040
1621-jun2828
179-sep8080
18Grand Total09993128036356
19
20
21
22Sum of Delta DaysColumn Labels
23Row LabelsDraw #1Draw #2Draw #3Draw #4Draw #5Draw #6Grand Total
24Customer C00
25Customer D0596548172
26Customer H03636
27Customer J0402880148
28Grand Total09993128036356
29
30
31
32
33
34
35
36
Sheet3
Cell Formulas
RangeFormula
E2:E12E2=IFERROR(DATEDIF(LOOKUP(2,1/($B$1:$B1=B2),($A$1:$A1)),A2,"D"),0)


this setup will utimately create this Stacked Bar graph.
 

Attachments

  • Screenshot 2022-07-27 122909.jpg
    Screenshot 2022-07-27 122909.jpg
    23.2 KB · Views: 29
Upvote 0
Solution
Thank you. I implemented your solution and it does create the correct pivot table and chart.

Is there any way to re-create this result strictly through the pivot table, though? This solution requires adding a column to the data but I would like to be able to completely replace the worksheet holding the data at any time with new data without needing to manipulate it at all. Ideally, I want to be able to export the data from Quickbooks to Excel, click refresh on my pivot tables and have everything work right away.
 
Upvote 0
I was able to make a little progress, but I'm still having trouble. My pivot table now calculates the time since the last payment like I want, but it breaks if there are any missing payments (i.e., if the first payment received from a customer in the given time period is draw #5, or if we haven't received a payment yet, or if a customer never paid draw #3 but did pay #2 and #4, then it breaks)

I changed the values to Sum of Date - Show Values As - Difference From - Memo - Previous. This is the closest I've gotten so far. I know the "broken" numbers are the serial number of the date of the payment, but I don't know how to handle them here.

Here's what my pivot table looks like now:

income and expenses TEST.xlsx
ABCDEFG
3Sum of DateColumn Labels
4Row LabelsDraw #1Draw #2Draw #3Draw #4Draw #5Draw #6
5Customer A406334327
6Customer B42353433-44767
7Customer C00044264-44264
8Customer D5965483559
9Customer E247835660
10Customer F244038-447430
11Customer G941941680
12Customer H0004433436
13Customer I3824513240
14Customer J4028806844
15Customer K-447430000
Sheet1
 
Upvote 0
Hi,

I'm not sure if this can be prevented as, at least to my knowledge, the pivot table does not have error handling when calculating with the standard functions.
That's the reason why i choose to add a helper column to the data.
As a tip:
  1. If you want to follow your chosen path, make sure you check what happens if a payment is mentioned twice in the data and insert the correct error handling
  2. Another option is to look at functionality in PowerQuery / PowerPivot.
 
Upvote 0
It's very frustrating to be so close to the result I want and not being able to get it. Out of curiosity and the principle of it, I'm going to keep fiddling and trying to solve this purely through the pivot table. But realistically, I will probably end up implementing jorismoerings' solution with the helper column. I'll accept that solution at that point.

Could there be a way to use a calculated field that removes the broken entries? I haven't been able to find one.
 
Upvote 0
Could there be a way to use a calculated field that removes the broken entries? I haven't been able to find one.
Yes, and probably not practically as a better option to PowerQuery/PowerPivot.
Old (and Still) available is the MDX language for calculating and querying. This requires use of the OLAP feature available. These complications and breadth of available references that are current just don't make it a good option. Its also a much steeper learning curve for all the pieces you need to pull together.

A lot of people prototype their PQ solutions on the worksheet and then use PQ to simplify the process since it automates your tasks.
 
Upvote 0
@jabu
Try this....
Add a new pivot table from your raw data and when adding the pivot table click the box at the bottom which will add the data to a data model.....then click ok to create the pivot table...

Once the pivot table on a new sheet....click inside of it and then goto the data tab on the file menu and click on Manage data.....this will open the power pivot window in excel.....here you can create the required calculate columns or measure to get your desired results....

Please note :: the new columns created will not be added to your main data source but will be available for use inside the pivot table list window in the excel sheet....

Hope this helps🤠
 
Upvote 0
I've been lacking time to work on this much, so I ended up using a helper column in the source data. I looked into PowerPivot/PowerQuery but I didn't have it in me to go and learn a bunch of new functions/syntax for this.

The helper column ended up being a bit more complicated than originally planned because my actual source data is more complex than the example data I posted. I modified jorismoerings' formula like so:
Excel Formula:
=IFERROR(DATEDIF(LOOKUP(2,1/(($A$1:$A1=A2)*($E$1:$E1=E2)*($H$1:$H1=H2)),$B$1:$B1),B2,"d"),0)

Column A is transaction type, column E is customer, column H is transaction account, and column B is date. So this function finds the most recent transaction that has the same type, customer, and account as the current transaction, and then returns the days elapsed since then. This allows me to compare days between all kinds of different things, not just draws.

Thanks everyone for your help.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

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