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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Flag Start of Series of Dates

Say for example I was looking to find out the number of instances someone took a period of days off sick...

However the sick days are stored per day rather than giving a start and end date.

How can I flag the start of each period of sick days (1 or zero depending on if the start of a sequence of dates)

Current Table

DateEmployee
24/06/18         A
24/06/18B
24/06/18C
25/06/18A
25/06/18C
26/06/18A
26/06/18D
27/06/18D


Desired Table

DateEmployeeFlag (Start of Sequence)
24/06/18        A1
24/06/18B1
24/06/18C1
25/06/18A0
25/06/18C0
26/06/18A0
26/06/18D1
27/06/18D0



As you can see the flag indicates 1 if there are no dates (for corresponding employee) in the table before it... or it indicates a zero if there are dates after, depends which way you want to look at it.

Any help would be really appreciated! Thanks!

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

You can create a calculated column as below to get it:

Flag (Start of Sequence) = 
VAR _preemp =
    CALCULATE (
        MAX ( 'Table'[Employee] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Employee] = EARLIER ( 'Table'[Employee] )
                && 'Table'[Date] < EARLIER ( 'Table'[Date] )
        )
    )
RETURN
    IF ( ISBLANK ( _preemp ), 1, 0 )

yingyinr_0-1627970416971.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

You can create a calculated column as below to get it:

Flag (Start of Sequence) = 
VAR _preemp =
    CALCULATE (
        MAX ( 'Table'[Employee] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Employee] = EARLIER ( 'Table'[Employee] )
                && 'Table'[Date] < EARLIER ( 'Table'[Date] )
        )
    )
RETURN
    IF ( ISBLANK ( _preemp ), 1, 0 )

yingyinr_0-1627970416971.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

@Anonymous I am thinking Cthulhu: Cthulhu - Microsoft Power BI Community. Alternatively, perhaps you get the MAXX of the date with matching criteria (EmployeeFlag) where the date is less than the current row's date. Then you check to see if there is only 1 day between them (just use simple subtraction) and then if that number is greater than 1 it is the start of a new sequence. Otherwise, it is not.


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

Fabric certifications survey

Certification feedback opportunity for the community.

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.