创建基于列中唯一值的 n 列的可伸缩 M 代码?

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

Scaleable M code to create n number of columns based on the unique values in a column?

问题

我有一个充满了客户购买数据的大型数据集。有两列对我特别感兴趣:购买日期和购买订单(1表示客户的第一次购买,2表示客户的第二次购买,依此类推)。

我想为每个独特的购买订单值创建一列,并填入相应的日期。

最终结果将是针对每位客户命名的第n次购买日期的n个列。

这是目前表格的样子:

这是所期望输出的示例:

如果表格格式不清楚,我很抱歉。

我不想手动完成这个操作,因为购买订单变量是可变的。但我意识到最终可能会有太多列,所以如果可以限制列的数量,那将会很棒。

提前感谢!

我尝试过手动操作,但这很繁琐并且受限制(购买订单的最大值目前超过了60)。

英文:

I have a large dataset filled with customer purchase data. There are two columns that are of specific interest to me: the date of a purchase and the order of the purchase (1 means it was the customer's first purchase, 2 means it was the customer's second purchase, and so on).

I would like to create a column for each unique purchase order value, and fill it with the corresponding date.

The end result would be n number of columns named "1st purchase date", "2nd purchase date", [...], "n purchase date" for each customer.

This is what the table looks like currently:

创建基于列中唯一值的 n 列的可伸缩 M 代码?

This is a sample of the desired output:

创建基于列中唯一值的 n 列的可伸缩 M 代码?

Apologies if the table formatting is unclear.

I don't want to do this manually, as the purchase order variable is variable. I am however conscious of the fact that there might be too many columns in the end, so if it's possible to add a limit to the number of columns, that would be fantastic.

Thanks in advance!

I tried to do this manually, but it's arduous and limiting (the max value of the purchase order is currently >60).

答案1

得分: 0

在Power Query中,点击选择“采购订单列”。

转换...旋转列...

对于数值列,请选择日期,并在高级选项中选择“不聚合”。

创建基于列中唯一值的 n 列的可伸缩 M 代码?

创建基于列中唯一值的 n 列的可伸缩 M 代码?

英文:

In powerquery, click select the Purchase Order Column

Transform ... pivot column...

for Values Column choose Date, and in Advanced Options pick Don't aggregate

创建基于列中唯一值的 n 列的可伸缩 M 代码?

创建基于列中唯一值的 n 列的可伸缩 M 代码?

huangapple
  • 本文由 发表于 2023年6月8日 16:13:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76429880.html
匿名

发表评论

匿名网友

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

确定