Forum Discussion
Incremental counter per day
- 8 months ago
Hi FabvE,
You can create this counter using a calculated column in Power BI. Here's the DAX formula:
Counter = RANKX( FILTER( 'YourTable', 'YourTable'[Date] = EARLIER('YourTable'[Date]) ), 'YourTable'[Date], , ASC, DENSE )If you need it based on a specific sort order (like timestamp within the day):
Counter = VAR CurrentDate = 'YourTable'[Date] VAR CurrentRow = 'YourTable'[YourUniqueID] // or timestamp column RETURN COUNTROWS( FILTER( 'YourTable', 'YourTable'[Date] = CurrentDate && 'YourTable'[YourUniqueID] <= CurrentRow ) )In Power Query (alternative):
- Sort by Date column
- Group by Date, add an "All Rows" aggregation
- Add custom column: Table.AddIndexColumn([AllRows], "Counter", 1, 1)
- Expand the nested table
The Power Query approach is more efficient for large datasets as it's computed during refresh rather than row-by-row like calculated columns.
Best regards!
PS: If you find this post helpful consider leaving kudos or mark it as solution
Hi FabvE,
You can create this counter using a calculated column in Power BI. Here's the DAX formula:
Counter =
RANKX(
FILTER(
'YourTable',
'YourTable'[Date] = EARLIER('YourTable'[Date])
),
'YourTable'[Date],
,
ASC,
DENSE
)If you need it based on a specific sort order (like timestamp within the day):
Counter =
VAR CurrentDate = 'YourTable'[Date]
VAR CurrentRow = 'YourTable'[YourUniqueID] // or timestamp column
RETURN
COUNTROWS(
FILTER(
'YourTable',
'YourTable'[Date] = CurrentDate &&
'YourTable'[YourUniqueID] <= CurrentRow
)
)In Power Query (alternative):
- Sort by Date column
- Group by Date, add an "All Rows" aggregation
- Add custom column: Table.AddIndexColumn([AllRows], "Counter", 1, 1)
- Expand the nested table
The Power Query approach is more efficient for large datasets as it's computed during refresh rather than row-by-row like calculated columns.
Best regards!
PS: If you find this post helpful consider leaving kudos or mark it as solution
Hi,
thx for the post. I forgot to mention that I use PQ in Excel not PowerBI...