indexing - Power Query 基于多列创建组编号

标签 indexing powerbi grouping powerquery

我有一张表格,列出了每年都有水果产品销售的公司。此外,数据被分类为一年中的多个季度。通过示例数据如下,

enter image description here

Company Year    Start   End Product Sale
C1  2020    04/01/20 00:00  6/30/2020 00:00 Apple   40
C1  2020    04/01/20 00:00  6/30/2020 00:00 Orange  60
C1  2020    04/01/20 00:00  6/30/2020 00:00 Grape   30
C1  2020    04/01/20 00:00  6/30/2020 00:00 Lemon   20
C1  2020    07/01/20 00:00  9/30/2020 00:00 Orange  82
C1  2020    07/01/20 00:00  9/30/2020 00:00 Lemon   46
C1  2020    07/01/20 00:00  9/30/2020 00:00 Pomegranate 68
C1  2020    07/01/20 00:00  9/30/2020 00:00 Papaya  25
C1  2021    04/01/21 00:00  6/30/2021 00:00 Apple   40
C1  2021    04/01/21 00:00  6/30/2021 00:00 Orange  60
C1  2021    04/01/21 00:00  6/30/2021 00:00 Grape   30
C1  2021    04/01/21 00:00  6/30/2021 00:00 Lemon   21
C1  2021    07/01/21 00:00  9/30/2021 00:00 Orange  82
C1  2021    07/01/21 00:00  9/30/2021 00:00 Lemon   46
C1  2021    07/01/21 00:00  9/30/2021 00:00 Pomegranate 68
C1  2021    07/01/21 00:00  9/30/2021 00:00 Papaya  25
                    
C2  2020    05/01/20 00:00  7/31/2020 00:00 Papaya  25
C2  2020    05/01/20 00:00  7/31/2020 00:00 Orange  65
C2  2020    05/01/20 00:00  7/31/2020 00:00 Lemon   48
C2  2020    05/01/20 00:00  7/31/2020 00:00 Apple   52
C2  2020    08/01/20 00:00  10/30/2020 00:00    Grape   98
C2  2020    08/01/20 00:00  10/30/2020 00:00    Orange  25
C2  2020    08/01/20 00:00  10/30/2020 00:00    Pomegranate 78
C2  2020    08/01/20 00:00  10/30/2020 00:00    Grape   97
C2  2021    05/01/21 00:00  7/31/2021 00:00 Papaya  25
C2  2021    05/01/21 00:00  7/31/2021 00:00 Orange  65
C2  2021    05/01/21 00:00  7/31/2021 00:00 Lemon   48
C2  2021    05/01/21 00:00  7/31/2021 00:00 Apple   52
C2  2021    08/01/21 00:00  10/30/2021 00:00    Grape   98
C2  2021    08/01/21 00:00  10/30/2021 00:00    Orange  25
C2  2021    08/01/21 00:00  10/30/2021 00:00    Pomegranate 78
C2  2021    08/01/21 00:00  10/30/2021 00:00    Grape   97

我想为每个公司、年份和季度创建一个索引号。我尝试使用如下所示的 AddIndexColumn 来执行此操作。

= Table.Group(#"Sorted Rows2", {"Company","Year","Start"}, {{"Data", each Table.AddIndexColumn(_, "Index", 1, 1), type table}})

上面的查询像下面这样转换了我的表。

enter image description here

但我想要如下结果,

enter image description here

公司一年中最早的季度应该索引为1,依此类推。有时,公司的第一季度将从04/01/2021开始,而最后一个季度将从01/01/2022开始。那么上述季度的公司年份为2022年。 我尝试了很多方法来转换表格,如上一张截图所示。但没有任何效果。如果我能以正确的方式做到这一点,我将不胜感激。

我们没有明确指示季度开始时间的字段。我们应该假设特定年份公司的最早日期是该季度的开始。

例如,在上面的示例中,对于 2020 年的公司 1,该季度从 04/01/2020 开始。对于 2020 年的公司 2,该季度从 05/01/2020 开始。

最佳答案

试试这个。

 rank= Table.AddRankColumn(#"Changed Type","Index", {{"Company", Order.Ascending}, {"Year", Order.Ascending}, {"Start", Order.Ascending}}, [RankKind = RankKind.Dense])

enter image description here

关于indexing - Power Query 基于多列创建组编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73319345/

相关文章:

javascript - 从 power bi public embed 中删除共享栏

powerbi - 使用 power bi 中的格式函数无法使用月份名称

tsql - 如何对父子行进行分组 (SQL)

mysql order by 分为两个不同的部分

数组元素和 charAt 变量之间的 Java 类型错误

Python Pandas 使用 dataframe.stack().value_counts() -- 如何获取计数对象的值?

sqlite判断是否使用索引

angular - 使用 Power REST API - 获取组中的页面时,有没有办法从报告中过滤掉 "Hidden"页面

Java流groupingBy并对多个字段求和

indexing - Julia:如何在另一个字符串数组中查找字符串(在字符串数组中)的位置