简体   繁体   English

如何在 Power Query 中为每个产品添加前一天销售的自定义列

[英]How to add custom column for previous day sales for each product in Power Query

I have this table:我有这张桌子:

Date日期 Product产品 Sales销售量
1/3/2021 2021 年 1 月 3 日 Apple苹果 10 10
1/3/2021 2021 年 1 月 3 日 Lemon柠檬 20 20
1/3/2021 2021 年 1 月 3 日 Mango芒果 30 30
1/4/2021 2021 年 1 月 4 日 Apple苹果 15 15
1/4/2021 2021 年 1 月 4 日 Lemon柠檬 25 25
1/5/2021 2021 年 1 月 5 日 Apple苹果 20 20
1/5/2021 2021 年 1 月 5 日 Lemon柠檬 20 20
1/5/2021 2021 年 1 月 5 日 Mango芒果 35 35

And I want to add a new column like this:我想添加一个这样的新列:

Date日期 Product产品 Sales销售量 Prev Day Sales前一天销售
1/3/2021 2021 年 1 月 3 日 Apple苹果 10 10 null null
1/3/2021 2021 年 1 月 3 日 Lemon柠檬 20 20 null null
1/3/2021 2021 年 1 月 3 日 Mango芒果 30 30 null null
1/4/2021 2021 年 1 月 4 日 Apple苹果 15 15 10 10
1/4/2021 2021 年 1 月 4 日 Lemon柠檬 25 25 20 20
1/5/2021 2021 年 1 月 5 日 Apple苹果 20 20 15 15
1/5/2021 2021 年 1 月 5 日 Lemon柠檬 20 20 25 25
1/5/2021 2021 年 1 月 5 日 Mango芒果 35 35 null null

You could add a column with previousDate and then join the table itself by Date-PreviousDate fields, then extract only the Sales field an rename it at wish.您可以添加一个包含 previousDate 的列,然后通过 Date-PreviousDate 字段连接表本身,然后仅提取 Sales 字段并随意重命名。

This should be null for days where no sales had taken place in the previous date.这应该是 null 表示上一个日期没有发生销售的天数。

Add a custom column with previous date as Date.AddDays([Date],-1) Then, in Home/Transform/Merge queries and select the same table to merge.添加一个自定义列,之前的日期为 Date.AddDays([Date],-1) 然后,在 Home/Transform/Merge 查询和 select 相同的表中进行合并。 Select the "Previous Date" field from the original and merge with the "Date" field on the second. Select 原始的“上一个日期”字段并与第二个上的“日期”字段合并。 Then CTRL-Click the field "Product" to use it also in the merge.然后 CTRL-单击“产品”字段以在合并中使用它。 Use a left outer join, so no rows are added.使用左外连接,因此不会添加任何行。 Expand the Sales column in the merged result and, here you go!展开合并结果中的销售列,然后就可以了! Greetings!问候!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM