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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
fapenar
Frequent Visitor

Calculate a date sequence on a row level per ID (in DAX)

Hi there, 

I have this data set where each patient goes through different treatments (each row is a new treatment).

fapenar_0-1694492496916.png

I would like to add a new column (using DAX) that creates a sequence of numbers from 1 to "N" for each Patient, being 1 assigned to the earliest date. 

This is what the new column should look like:

Patient Created on (d/mm/yyyy)  Treatment number (calculated column)
Patient A   16/08/2023    3

Patient A

    5/05/2023    2 
Patient A   25/03/2023    1
Patient B   13/08/2023    2
Patient B    5/05/2023     1 
Patient C   19/06/2023    1
Patient D    8/09/2023    2
Patient D   14/07/2023    1


Thanks!

1 ACCEPTED SOLUTION
vicky_
Super User
Super User

Try the following formula in a calculated column:

Treatment Number = COUNTROWS(FILTER('Table', 'Table'[ Created on (d/mm/yyyy)] <= EARLIER('Table'[ Created on (d/mm/yyyy)]) && 'Table'[Patient] = EARLIER('Table'[Patient])))

View solution in original post

2 REPLIES 2
fapenar
Frequent Visitor

It's working perfectly. Thanks, Vicky!

vicky_
Super User
Super User

Try the following formula in a calculated column:

Treatment Number = COUNTROWS(FILTER('Table', 'Table'[ Created on (d/mm/yyyy)] <= EARLIER('Table'[ Created on (d/mm/yyyy)]) && 'Table'[Patient] = EARLIER('Table'[Patient])))

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.