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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

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 @Anonymous 

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
LinkedIn

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.