Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
JimsonBonilla
Frequent Visitor

Sequential Count rows with same date

Hello, everybody. Hope all the best for you.

 

I have a small request. I have my sales data registered weekly by department and store. I use a date from within the week (from monday to friday) as my date column in my table.

I want to create a sequential column for each week by store. For example, in the week 1, all the rows correspondent to departments in store A should have the value of 1, and for the week 2 they should have the value of 2.

 

Here is an example of my data:

 

DepartmentStoreDateUnit Sales
1A10/02/2023181
2A10/02/202353
3A10/02/202354
4A10/02/202366
1B09/02/2023112
2B09/02/2023145
3B09/02/2023177
1C08/02/202365
2C08/02/202350
1D09/02/2023112
2D09/02/2023105
3D09/02/2023112
1A17/02/2023117
2A17/02/2023138
3A17/02/2023175
4A17/02/2023194
1B15/02/2023191
2B15/02/202357
3B15/02/2023198
1C17/02/2023166
2C17/02/2023173
3C17/02/2023119
1D16/02/2023135
2D16/02/202394
3D16/02/202395
1E14/02/2023167
2E14/02/2023120
3E14/02/202391
4E14/02/202360

 

I've used the current formula to try to get it in my calculated column (I need this info as a column):

 

 

 

 

COUNTX(
    FILTER(
            ALL(DepartmentSales_DB),
            DepartmentSales_DB[Store] = EARLIER(DepartmentSales_DB[Store]) &&
            DepartmentSales_DB[Date]<=EARLIER(DepartmentSales_DB[Date])
            ),1
        )

 

 

 

 

 But this formula returns me the next results

DepartmentStoreDateUnit SalesResults
1A10/02/20231814
2A10/02/2023534
3A10/02/2023544
4A10/02/2023664
1A17/02/20231178
2A17/02/20231388
3A17/02/20231758
4A17/02/20231948

 

Instead of 4, the value should be 1, and instead of 8, 2.

 

Can someone help me figuring out where is the problem? Thank you.

1 REPLY 1
OwenAuger
Super User
Super User

Hello @JimsonBonilla 

The RANK function is useful here.

Try this:

Sequential Rank Calculated Column = 
RANK (
    DENSE,
    ALL ( DepartmentSales_DB[Store], DepartmentSales_DB[Date] ),
    ORDERBY ( DepartmentSales_DB[Date] ),
    PARTITIONBY ( DepartmentSales_DB[Store] )
)

 Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.