Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
I am working for a hotel company, and we have a list of Guest ID's and their Stay dates, I want to determine which stays were a first, middle or last day.
ID Stay Date Frist Middle Last
2 | 1/1/2018 | First Day |
2 | 1/2/2018 | MIddle Day |
2 | 1/3/2018 | Last Day |
\
Any tips?
Solved! Go to Solution.
Try with this formula :
Status = IF( ISBLANK(DateAdd(Guests[Dates];-1;DAY));"First Day"; IF ( ISBLANK(DateAdd(Guests[Dates];1;DAY) ) ; "Last Day" ; "Middle Day" ) )
Hi, try with this calculated column:
Day = VAR StayDate = Table1[StayDate] - 1 VAR StayDate_plus1 = Table1[StayDate] + 1 RETURN IF ( COUNTROWS ( FILTER ( Table1; Table1[StayDate] = StayDate && Table1[GuesID] = EARLIER ( Table1[GuesID] ) ) ) < 1; "First"; IF ( COUNTROWS ( FILTER ( Table1; Table1[StayDate] = StayDate_plus1 && Table1[GuesID] = EARLIER ( Table1[GuesID] ) ) ) < 1; "Last"; "Middle" ) )
Regards
Victor
yes
Hello,
I created this table :
Created this column :
Status = IF( Guests[Dates]=CALCULATE ( MINX( Guests; Guests[Dates]) ; ALLEXCEPT ( Guests ; Guests[Guests] ) );"First Day"; IF( Guests[Dates]=CALCULATE ( MAXX( Guests; Guests[Dates]) ; ALLEXCEPT ( Guests ; Guests[Guests] ) ); "Last Day" ;"Middle Day" ))
The result :
I hope this will help
All of those days you provided should actually be listed as first days becuase the previous day they did not stay with us.
if the guest stays with us on the 1st, 2nd and 3rd the 1st should be a first day the 2nd a Middle and the 3rd day a last.
Then if the same guest stays with us on the 5th-6th the 5th should be a new first day then the 6th a last day.
Does that make sense?
Try with this formula :
Status = IF( ISBLANK(DateAdd(Guests[Dates];-1;DAY));"First Day"; IF ( ISBLANK(DateAdd(Guests[Dates];1;DAY) ) ; "Last Day" ; "Middle Day" ) )
Amazing thank you!
you are right 😞 . I saw this when I applied to my larger dataset, any way to work around?
Hi, try with this calculated column:
Day = VAR StayDate = Table1[StayDate] - 1 VAR StayDate_plus1 = Table1[StayDate] + 1 RETURN IF ( COUNTROWS ( FILTER ( Table1; Table1[StayDate] = StayDate && Table1[GuesID] = EARLIER ( Table1[GuesID] ) ) ) < 1; "First"; IF ( COUNTROWS ( FILTER ( Table1; Table1[StayDate] = StayDate_plus1 && Table1[GuesID] = EARLIER ( Table1[GuesID] ) ) ) < 1; "Last"; "Middle" ) )
Regards
Victor
Amazing!
Any way to do this in DAX without a calucated column. I understand if not. Thanks so much for your help! lifesaver!
can you post your sample results? my syntax is different than what this sample is
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
87 | |
83 | |
82 | |
65 | |
49 |
User | Count |
---|---|
135 | |
111 | |
100 | |
65 | |
62 |