Forum Discussion
Grouping continuous working dates by name or ID
- Anonymous4 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.
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.
- Honne20214 years ago
Helper II
Thank you for the help. I just had to re-write the code a little bit but it worked, overall! Thank you again!