Diff between two dates summarized by months

spurs50

New Member
Joined
Aug 6, 2020
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I haven't been able to work out how to do in power pivot or normal formulas as it requires using the average of each month and dividing by the occurrences in each month to get an average.
The problem is the start and end dates are random, and days in between can be any number of days between different months and years.
Some rows may be between 1st Sep 2020, and 20th Dec 2020, or just be a week long as an example below. All dates are different and randomn

I would like to get a table of per month calculation for each country in a pivot table format or similar.
Example below raw data

Country Plant Start End Days Volume
Brazil Rio 10/15/2022 12/20/2022 67 50
Brazil Brasilia 02/06/2023 03/07/2023 30 100
Colombia Bogota 11/01/2022 12/05/2022 35 30

The answer should look like below for each plant. And then I can summarize by country. Think pivot tables are impossible and needs formulas or vba?
Any help would be greatly appreciated

BrazilBrazilColombia
RioBrasiliaBogota
Oct-2227.420.000.00
Nov-2250.000.0030.00
Dec-2232.260.004.84
Jan-230.000.000.00
Feb-230.0082.140.00
Mar-230.0022.580.00
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Can you explain why, for example, Brazil>Rio is 27.42, 50.00 and 32.36? And why the others are they way they are? (e.g. What is the math you used to arrive at those values?) It's not making sense to me at this point.
 
Upvote 0
Can you explain why, for example, Brazil>Rio is 27.42, 50.00 and 32.36? And why the others are they way they are? (e.g. What is the math you used to arrive at those values?) It's not making sense to me at this point.
Sorry I should have been clearer. Rio has 50 power used in each day between Oct 15th and 20th Dec. Oct has 31 days, started on 15th Oct, so it used 17 days in Oct. (50*17)/31 = 27.42
It used power each day in Nov, so avg 50 (50*30)/30 days Nov). Dec finished on 20th Dec = 20 days. (50*20) /31 days in Dec = 32.26
Thanks
 
Upvote 0
Perhaps this will work? I used helper cells in rows 8-10 so I could shorten the formulas in rows 11+.

Book1
ABCDEF
1CountryPlantStartEndDaysVolume
2BrazilRio10/15/202212/20/20226750
3BrazilBrasilia2/6/20233/7/202330100
4ColombiaBogota11/1/202212/5/20223530
5
6BrazilBrazilColombia
7RioBrasiliaBogota
810/15/20222/6/202311/1/2022
912/20/20223/7/202312/5/2022
105010030
11Aug-220.000.000.00
12Sep-220.000.000.00
13Oct-2227.420.000.00
14Nov-2250.000.0030.00
15Dec-2232.260.004.84
16Jan-230.000.000.00
17Feb-230.0082.140.00
18Mar-230.0022.580.00
19Apr-230.000.000.00
20May-230.000.000.00
21Jun-230.000.000.00
22Jul-230.000.000.00
23Aug-230.000.000.00
24Sep-230.000.000.00
25Oct-230.000.000.00
26Nov-230.000.000.00
27Dec-230.000.000.00
Sheet3
Cell Formulas
RangeFormula
E2:E4E2=DATEDIF(C2,D2,"d")+1
B8:D8B8=INDEX($C$2:$C$4,MATCH(B$6&B$7,$A$2:$A$4&$B$2:$B$4,0))
B9:D9B9=INDEX($D$2:$D$4,MATCH(B$6&B$7,$A$2:$A$4&$B$2:$B$4,0))
B10:D10B10=INDEX($F$2:$F$4,MATCH(B$6&B$7,$A$2:$A$4&$B$2:$B$4,0))
B11:D27B11=IF(OR(EOMONTH($A11,0)<B$8,$A11>B$9),0,IF(YEAR(B$8)&MONTH(B$8)=YEAR($A11)&MONTH($A11),((EOMONTH($A11,0)-B$8+1)*B$10)/DAY(EOMONTH($A11,0)),IF(YEAR(B$9)&MONTH(B$9)=YEAR($A11)&MONTH($A11),(DAY(B$9)*B$10)/DAY(EOMONTH($A11,0)),B$10)))
 
Upvote 0
Thanks so much for this Z51. I have been away this long weekend but going to try it out. The problem is that I have thousands of rows so wanted to avoid those helper cells and summarize per country only and months.
Is there a way for the only helpers to be months and country? I am going to try and figure it out in the meantime.
Many thanks for your help
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

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