如何在PowerQuery中提取每个分组的最大列金额?

huangapple go评论67阅读模式
英文:

How to extract max amount of column for each group in powerquery?

问题

在Excel的Power Query中,你可以按照以下步骤来实现你的需求:

  1. 打开Power Query编辑器
    在Excel中,选择你的数据范围,然后点击“数据”选项卡,在“获取与转换数据”组中选择“从表格/范围”。这将会打开Power Query编辑器。

  2. 分组数据
    在Power Query编辑器中,选择"Year"、"Month"和"Name"列,然后点击"开始"选项卡中的"分组"按钮。在弹出的对话框中,选择"Year"、"Month"和"Name"列,并且选择"最大"作为聚合操作。点击"确定"。

  3. 展开分组后的数据
    在分组后的结果中,你会看到一个新的列,名为"Max of Qty"(或类似的名称)。点击该列旁边的小方向箭头,选择"展开"。在展开对话框中,选择需要的列(Year、Month、Name和Max of Qty),然后点击"确定"。

  4. 重命名列(可选):
    如果需要,你可以右键点击列标题,选择"重命名"来修改列的名称,使其符合你的输出要求。

完成以上步骤后,你将得到你期望的输出结果。希望这对你有所帮助!

英文:

I am working on some data in powerquery in Excel. I need to make a query that returns unique values of the original table. The original table has a structure like below.

Year	month	 name   qty
2019	Jan	       n	100
2019	Jan	       n	200
2019	Jan	       m	300
2019	Jan	       m	400
2019	feb	       n	1000
2019	feb	       n	20
2019	feb	       m	300
2019	feb	       m	500
2020	Jan	       n	100
2020	Jan	       n	200
2020	Jan	       m	300
2020	Jan	       m	400
2020	feb	       n	1000
2020	feb	       n	20
2020	feb	       m	300
2020	feb	       m	500

I need to extract an output like below

year	month	product	MaxQty
2019	feb	       m	500
2019	feb	       n	1000
2019	Jan	       m	400
2019	Jan	       n	200
2020	feb	       m	500
2020	feb	       n	1000
2020	Jan	       m	400
2020	Jan	       n	200

In Sql, I can extract this output with below line of code.

SELECT year,month,name,max(qty) as MaxQty
FROM Table1 group by year,month,name;

How can I do it in power query of excel?

I used the following command:

=List.Distinct(Table1[Year]) 

but it worked on one column and I could not expand it to multiple columns to extract the max price of each product in year and month.

I need to do it in Power query. I would appreciate if you could advice.

答案1

得分: 2

点击选择年份、月份和名称列

右键分组

取数量列的最大值

英文:

click select the year, month and name columns

Right click group by

take the maximum of the qty column

如何在PowerQuery中提取每个分组的最大列金额?

huangapple
  • 本文由 发表于 2023年5月14日 03:29:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76244539.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定