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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kattlees
Post Patron
Post Patron

Adding sequence column based on time and surgeon

If I have a table that lists surgeon name, OR, Start Time like this:

 

JONES JANEOR 69:00
JONES JANEOR 57:45
JONES JANEOR 67:00
JONES JANEOR 511:45
JONES JANEOR 611:00
JONES JANEOR 510:15
LOU BETTYOR 410:30
LOU BETTYOR 48:30
LOU BETTYOR 315:15
LOU BETTYOR 47:30
LOU BETTYOR 311:30
LOU BETTYOR 412:00
LOU BETTYOR 39:30

 

How do I get a "sequence column" added that would put a number starting at 1 that shows the order of surgeries.

 

Would wind up looking like this?

JONES JANEOR 69:003
JONES JANEOR 57:452
JONES JANEOR 67:001
JONES JANEOR 511:456
JONES JANEOR 611:005
JONES JANEOR 510:154
LOU BETTYOR 410:304
LOU BETTYOR 48:302
LOU BETTYOR 315:157
LOU BETTYOR 47:301
LOU BETTYOR 311:305
LOU BETTYOR 412:006
LOU BETTYOR 39:303
1 ACCEPTED SOLUTION

I was able to figure out my own answer by piecing together other answers.

 

I gave each case of the day a rank by surgeon:

PreviousRowSales =
VAR Index = Table1[Rank] - 1
RETURN
    CALCULATE (
        SUM ( Table1[Current Month Sales] ),
        FILTER ( ALLEXCEPT ( Table1, Table1[Customer] ), Table1[Rank] = Index )
    )

 

Then got this calculated column:

PreviousMDOut =
VAR Index = V_EWS_TASK_RECORD[Rank] - 1
VAR SDATE = V_EWS_TASK_RECORD[OR Times Final.SCHDT]
RETURN
CALCULATE (
SUM ( V_EWS_TASK_RECORD[MD out] ),
FILTER ( ALLEXCEPT ( V_EWS_TASK_RECORD, V_EWS_TASK_RECORD[OR Times Final.SURGEON] ), V_EWS_TASK_RECORD[Rank] = Index && V_EWS_TASK_RECORD[OR Times Final.SCHDT]=SDATE)

View solution in original post

8 REPLIES 8
v-xjiin-msft
Solution Sage
Solution Sage

Hi @kattlees,

 

To achieve your requirement, you can try following calculated column.

 

Rank =
RANKX (
    CALCULATETABLE ( surgeon, ALLEXCEPT ( surgeon, surgeon[surgeon] ) ),
    surgeon[Start Time],
    ,
    ASC,
    DENSE
)

1.PNG

 

Thanks,
Xi Jin.

This works great but I forgot one thing - how would you do it by date, time?

 

So rank surgeries for Surgeon A yesterday 1-? and surgeries for surgeon A today 1-?

Hi @kattlees,

 

What did you mean date, time? A column in datetime type? Or two columns date and time?

 

Could you please share us some sample data if possible?

 

Thanks,
Xi Jin.

I was able to figure out my own answer by piecing together other answers.

 

I gave each case of the day a rank by surgeon:

PreviousRowSales =
VAR Index = Table1[Rank] - 1
RETURN
    CALCULATE (
        SUM ( Table1[Current Month Sales] ),
        FILTER ( ALLEXCEPT ( Table1, Table1[Customer] ), Table1[Rank] = Index )
    )

 

Then got this calculated column:

PreviousMDOut =
VAR Index = V_EWS_TASK_RECORD[Rank] - 1
VAR SDATE = V_EWS_TASK_RECORD[OR Times Final.SCHDT]
RETURN
CALCULATE (
SUM ( V_EWS_TASK_RECORD[MD out] ),
FILTER ( ALLEXCEPT ( V_EWS_TASK_RECORD, V_EWS_TASK_RECORD[OR Times Final.SURGEON] ), V_EWS_TASK_RECORD[Rank] = Index && V_EWS_TASK_RECORD[OR Times Final.SCHDT]=SDATE)

Hi @kattlees,

 

I'm gald to hear that you have resolved your issue. Please kindly mark your solution as answer. It will help others with relevant issue find the answer more easily.

 

Thanks,
Xi Jin.

Greg_Deckler
Super User
Super User

This one does it by Surgeon:

 

Rank3 = RANKX(FILTER(ALL(Surgeries),[Surgeon]=EARLIER([Surgeon])),[Time],,ASC)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

This one does it by OR:

 

Rank2 = RANKX(FILTER(ALL(Surgeries),[OR]=EARLIER([OR])),[Time],,ASC)

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

As a column in your table:

 

Rank = RANKX(Surgeries,[Time],,ASC)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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