I have a table of the list of companies that have their fruit product sales every year. Also, the data is categorized into multiple quarters of the year. By sample data is as below,
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
I wanted to create an index number of every Company, Year, and Quarter. I tried to do this using AddIndexColumn like below.
= Table.Group(#"Sorted Rows2", {"Company","Year","Start"}, {{"Data", each Table.AddIndexColumn(_, "Index", 1, 1), type table}})
The above query transformed my table like the below.
But I want the result like below,
The earliest Quarter of a Company of the year should index as 1 and so on., Sometimes the first quarter of the company would start from 04/01/2021, and the last quarter would begin from 01/01/2022. Then the year of the company in the above quarter will be 2022. I tried many ways to transform the table as above the last screenshot. But nothing was working. It would be really appreciated if I get a proper way of doing this.
We didn't have a field explicitly to indicate when a quarter starts. We should assume the earliest date of a Company of the particular year would be the start of the quarter.
For Example, in the Above Example, the quarter starts from 04/01/2020 for Company 1 of 2020. The Quarter starts on 05/01/2020 for Company 2 of 2020.




