[英]Excel - Is there a way to SUM values based on 2 associated criteria and then find the MAX summed value?
I have a list of buildings by city and building name which all have 5 items associated to them and each have a monetary value. 我有一个按城市和建筑物名称列出的建筑物列表,所有建筑物都有5个与之相关的项目,每个项目都有货币价值。 I am trying the sum these 5 values based on the city and building name and then of those sums I want to output the maximum value.
我正在尝试根据城市和建筑物名称将这5个值相加,然后在这些和中我想输出最大值。
I have tried using this code in the Value Cell F4 from the image but it only returns the sum of the first 5 items from the table. 我尝试在图像的值单元格F4中使用此代码,但它仅返回表中前5个项目的总和。
=MAX(SUMIFS(Table1[Value],Table1[Location],INDEX(Table1[Location],,1)))
I am not sure how to store a list of all the summed values of the different buildings and then output the max value. 我不确定如何存储不同建筑物的所有求和值的列表,然后输出最大值。
I would also like the City and Building name associated to the maximum summed value be output in the other 2 cells G4 and H4 我还希望与最大和值关联的城市和建筑物名称在其他2个单元格G4和H4中输出
For the max sum 对于最大和
=MAX(SUMIFS(Table1[Value],Table1[Location],Table1[Location],Table1[Building],Table1[Building]))
For the City 为城市
=INDEX(Table1[Location],MATCH(F4,SUMIFS(Table1[Value],Table1[Location],Table1[Location],Table1[Building],Table1[Building]),0))
and for the Building 对于建筑
=INDEX(Table1[Building],MATCH(F4,SUMIFS(Table1[Value],Table1[Location],Table1[Location],Table1[Building],Table1[Building]),0))
all entered as array formulas using Ctrl Shift Enter 全部使用Ctrl Shift 输入为数组公式
You can also do this using Power Query
. 您也可以使用
Power Query
进行此操作。
This would be particularly useful in the event two buildings have the same value , as I have adjusted the data below to show. 如果两座建筑物的值相同 ,这将特别有用,因为我已经调整了以下数据以显示。
Sum
Sum
汇总 Except for the Filter
operation, which needs to be entered manually in the Advanced Editor
, all of the operations can be done using the Power Query GUI. 除了需要在“
Advanced Editor
手动输入的“ Filter
操作外,所有操作都可以使用Power Query GUI进行。
M-Code M代码
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Location", type text}, {"Building", type text}, {"Item", type text}, {"Value", Currency.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Location", "Building"}, {{"Total Values", each List.Sum([Value]), type number}}),
#"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each ([Total Values] = List.Max(#"Grouped Rows"[Total Values]))),
#"Reordered Columns" = Table.ReorderColumns(#"Filtered Rows",{"Total Values", "Location", "Building"}),
#"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Total Values", "Value"}})
in
#"Renamed Columns"
Source Data 源数据
Max Values 最大值
There's an easy workaround to that. 有一个简单的解决方法。 If it's not a problem, you can add a column to your table with the sum of that building/location
如果没问题,您可以在表格中添加一列,其中包含该建筑物/位置的总和
=SUMIFS(Table1[Value],Table1[Location],[@[Location]],Table1[Building],[@[Building]])
(Something like this in your table) (表格中的内容)
And then do the MAX of that new column 然后执行该新列的MAX
Edit: 编辑:
By the way, you can also do that with a pivot table, and filter the top 1 value of the sum 顺便说一句,您也可以使用数据透视表进行此操作,并过滤总和的前1个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.