calculate monthly averages

lcastanheiro

New Member
Joined
Feb 21, 2019
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hi, I have data arranged data table how do I calculate the averages of C,D,E and F and tabulate it by year and month as in the Average China Prices table?
Thanks for you help
summary table.xlsx
BCDEFGHIJKLMNOP
3PO Spot Market Price (unit: RMB/mt)Average China PO prices RMB/ton SCI
4DateShandongNorth ChinaEast ChinaNortheast China2023202220212020201920182017
51/4/202210,35010,65010,40010,650January¥ 9,134¥ 10,998¥ 18,268¥ 9,591¥ 7,902¥ 10,544¥ 10,995
61/5/202210,55010,85010,60010,850February¥ 9,690¥ 11,627¥ 17,068¥ 8,716¥ 7,997¥ 10,509¥ 10,621
71/6/202210,65011,00010,80010,950March¥ 10,580¥ 11,902¥ 19,135¥ 8,208¥ 8,360¥ 10,590¥ 9,926
81/7/202210,75011,05010,80011,050April¥ 9,698¥ 11,301¥ 18,099¥ 7,694¥ 8,367¥ 10,634¥ 9,880
91/10/202210,75011,05010,70011,050May¥ 9,858¥ 11,119¥ 17,987¥ 9,018¥ 7,507¥ 10,790¥ 9,378
101/11/202210,75011,05010,70011,050June¥ 9,474¥ 10,674¥ 13,586¥ 9,615¥ 7,180¥ 10,266¥ 9,937
111/12/202210,75011,05010,65011,050July¥ 9,331¥ 9,083¥ 16,093¥ 10,136¥ 7,435¥ 9,801¥ 10,358
121/13/202210,52510,77510,45010,750August¥ 9,358¥ 9,030¥ 16,545¥ 12,833¥ 7,965¥ 10,454¥ 12,182
131/14/202210,52510,77510,45010,750September¥ 10,272¥ 16,070¥ 16,043¥ 8,126¥ 10,919¥ 10,957
141/17/202210,85011,17510,65011,075October¥ 9,882¥ 17,898¥ 18,416¥ 8,074¥ 10,357¥ 11,735
151/18/202210,85011,17510,75011,075November¥ 9,241¥ 15,474¥ 16,671¥ 7,729¥ 9,491¥ 11,761
161/19/202211,00011,37510,85011,200December¥ 9,032¥ 13,287¥ 17,285¥ 7,762¥ 9,295¥ 12,582
171/20/202211,05011,40011,00011,200
181/21/202211,15011,50011,05011,300
191/24/202211,20011,55011,15011,300
201/25/202211,15011,50011,15011,300
211/26/202211,15011,50011,15011,300
221/27/202211,15011,50011,10011,300
231/28/202211,15011,50011,10011,300
241/29/202210,95011,35011,05011,200
251/30/202210,95011,35011,05011,200
262/7/202210,95011,35011,15011,200
272/8/202211,15011,52511,25011,400
282/9/202211,25011,62511,40011,500
292/10/202211,55011,90011,60011,850
302/11/202211,65012,00011,60011,950
312/14/202211,85012,10011,80012,150
Sheet1
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Power Query
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Date"}, "Attribute", "Value"),
    #"Inserted Year" = Table.AddColumn(#"Unpivoted Other Columns", "Year", each Date.Year([Date]), Int64.Type),
    #"Inserted Month Name" = Table.AddColumn(#"Inserted Year", "Month Name", each Date.MonthName([Date]), type text),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted Month Name",{"Date"}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Removed Columns", {{"Year", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Removed Columns", {{"Year", type text}}, "en-US")[Year]), "Year", "Value", List.Sum)
in
    #"Pivoted Column"
AttributeMonth Name2022
East ChinaFebruary68800
East ChinaJanuary227600
North ChinaFebruary70500
North ChinaJanuary235125
Northeast ChinaFebruary70050
Northeast ChinaJanuary232900
ShandongFebruary68400
ShandongJanuary228200


If you want China not by region then:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Date"}, "Attribute", "Value"),
    #"Inserted Year" = Table.AddColumn(#"Unpivoted Other Columns", "Year", each Date.Year([Date]), Int64.Type),
    #"Inserted Month Name" = Table.AddColumn(#"Inserted Year", "Month Name", each Date.MonthName([Date]), type text),
    #"Grouped Rows" = Table.Group(#"Inserted Month Name", {"Year", "Month Name"}, {{"Average", each List.Average([Value]), type number}})
in
    #"Grouped Rows"

YearMonth NameAverage
2022January10997.91667
2022February11572.91667
 
Upvote 0
Hello alansidman, I appreciate your reply, but I have no clue how to use power query at all :oops:, and the result is not quite what I was looking for, but rather have the months in rows and the year in columns, so I could complement the master set already have. Thank you for your effort.
 
Upvote 0
Try:
Drag formula across and down as needed.

Book2
BCDEFGHIJKLMNOP
3PO Spot Market Price (unit: RMB/mt)Average China PO prices RMB/ton SCI
4DateShandongNorth ChinaEast ChinaNortheast China2023202220212020201920182017
51/4/202210350106501040010650January01099800000
61/5/202210550108501060010850February01157300000
71/6/202210650110001080010950March0000000
81/7/202210750110501080011050April0000000
91/10/202210750110501070011050May0000000
101/11/202210750110501070011050June0000000
111/12/202210750110501065011050July0000000
121/13/202210525107751045010750August0000000
131/14/202210525107751045010750September0000000
141/17/202210850111751065011075October0000000
151/18/202210850111751075011075November0000000
161/19/202211000113751085011200December0000000
171/20/202211050114001100011200
181/21/202211150115001105011300
191/24/202211200115501115011300
201/25/202211150115001115011300
211/26/202211150115001115011300
221/27/202211150115001110011300
231/28/202211150115001110011300
241/29/202210950113501105011200
251/30/202210950113501105011200
262/7/202210950113501115011200
272/8/202211150115251125011400
282/9/202211250116251140011500
292/10/202211550119001160011850
302/11/202211650120001160011950
312/14/202211850121001180012150
Sheet1
Cell Formulas
RangeFormula
J5:P16J5=AVERAGE(FILTER($C$5:$F$31,(YEAR($B$5:$B$31)=YEAR(J$4))*(MONTH($B$5:$B$31)=MONTH($I5)),0))
 
Upvote 1
Solution
Let me enlighten you about Power Query since you are using O365 for which it is integral.

Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

- Follow this link to learn how to install Power Query in Excel 2010 / 2013.

- Follow this link for an introduction to Power Query functionality.

- Follow this link for a video which demonstrates how to use Power Query code provided.

Also, I have shown results in two different formats which can be interchanged to provide you with the design look you desire.
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!
Cross posted at: Tabulating averages by month and year
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,173
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