Forum Discussion

Honne2021's avatar
Honne2021
Icon for Helper II rankHelper II
4 years ago
Solved

Grouping continuous working dates by name or ID

Hi, I had been looking around for a solution to this but I couldnt find one. I usually see the opposite of my problem! I need to write it through M code or through Power Query.  My report looks l...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Honne2021 ,

    I have created a simple sample, please reer to it to see if it helps you.

    Create 2 columns.

    Column first day of leave =
    VAR _maxdate =
        CALCULATE (
            MAX ( 'Table'[Date of Leave] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[month] = EARLIER ( 'Table'[month] )
                    && 'Table'[year] = EARLIER ( 'Table'[year] )
                    && 'Table'[Reason] = EARLIER ( 'Table'[Reason] )
                    && 'Table'[Employee ] = EARLIER ( 'Table'[Employee ] )
            )
        )
    VAR _mindate =
        CALCULATE (
            MIN ( 'Table'[Date of Leave] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[month] = EARLIER ( 'Table'[month] )
                    && 'Table'[year] = EARLIER ( 'Table'[year] )
                    && 'Table'[Reason] = EARLIER ( 'Table'[Reason] )
                    && 'Table'[Employee ] = EARLIER ( 'Table'[Employee ] )
            )
        )
    VAR _datebetween =
        DATEDIFF ( _mindate, _maxdate, DAY )
    RETURN
        IF ( _datebetween <= 7, _mindate, ( 'Table'[Date of Leave] ) )
    
    Column last day of leave =
    VAR _count =
        CALCULATE (
            COUNT ( 'Table'[Reason] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[month] = EARLIER ( 'Table'[month] )
                    && 'Table'[year] = EARLIER ( 'Table'[year] )
                    && 'Table'[Reason] = EARLIER ( 'Table'[Reason] )
                    && 'Table'[Employee ] = EARLIER ( 'Table'[Employee ] )
            )
        )
    VAR _maxdate =
        CALCULATE (
            MAX ( 'Table'[Date of Leave] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[month] = EARLIER ( 'Table'[month] )
                    && 'Table'[year] = EARLIER ( 'Table'[year] )
                    && 'Table'[Reason] = EARLIER ( 'Table'[Reason] )
                    && 'Table'[Employee ] = EARLIER ( 'Table'[Employee ] )
            )
        )
    VAR _mindate =
        CALCULATE (
            MIN ( 'Table'[Date of Leave] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[month] = EARLIER ( 'Table'[month] )
                    && 'Table'[year] = EARLIER ( 'Table'[year] )
                    && 'Table'[Reason] = EARLIER ( 'Table'[Reason] )
                    && 'Table'[Employee ] = EARLIER ( 'Table'[Employee ] )
            )
        )
    VAR _datebetween =
        DATEDIFF ( _mindate, _maxdate, DAY )
    RETURN
        IF ( _datebetween <= 7, _maxdate, ( 'Table'[Date of Leave] ) )
    

     

    If I have misunderstood your meaning, please provide mroe details with your desired output and pbix file without privacy information.

     

     

    Best Regards

    Community Support Team _ Polly

     

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