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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
MichelleRA_24
Regular Visitor

Continuous Streak

Hi to all!

I need your help to create a formula to mark the initial date of each group of consecutive dates and maintain that same date for all dates within each group. It is necessary to use a formula that identifies the start of each group of consecutive dates and marks that date for all rows within the group.

The idea is in the "Vacations Start Date" column, dates are listed, some consecutive and others not.

The "If days" column determines if each date is consecutive with the one above: it marks 0 if not consecutive, and 1 if consecutive.

The "Part" column indicates that for consecutive dates, it shows the same start date where the pattern begins at zero.

The "Count Days" column displays the number of consecutive days, excluding weekends.

Lastly, the "Consecutive days" column repeats the total count of consecutive days for each row

 

I only have two columns, "Vacations Star Date"  and "Return" Could you please guide me on creating the others?

Expected result:

MichelleRA_24_0-1719407252301.png

 

 

2 ACCEPTED SOLUTIONS
v-linyulu-msft
Community Support
Community Support

HI,@MichelleRA_24 

Regarding the issue you raised, my solution is as follows:

1. I have created the following table and the column names and data are the data you have given:

vlinyulumsft_0-1719461644560.png

2.First, we need to add a sequence to the powerquery:

vlinyulumsft_1-1719461662710.png

3.Secondly, use the following calculation column to determine whether it is continuous:

 

IF days = 
VAR currentday1=[Vacations Start Date]
VAR predate=CALCULATE(MAX('Table'[Vacations Start Date]),FILTER('Table','Table'[Vacations Start Date]<currentday1))
RETURN IF(predate+1=currentday1,1,0)

 

4.Then, relying on the previous calculation column, the grouping column is generated:

 

group = 
VAR CurrentIndex1 = [Index]
VAR PreviousIndex1= CALCULATE(MAX('Table'[Index]), FILTER('Table', 'Table'[Index]<=CurrentIndex1 && 'Table'[IF days]=0))
RETURN PreviousIndex1

 

5.You can then proceed to create calculation columns that meet your needs:

 

RETURN = 'Table'[Vacations Start Date]+1
Count days = 
VAR CurrentIndex2 = [Index]
VAR PreviousIndex = CALCULATE(MAX('Table'[Index]), FILTER('Table', 'Table'[Index]<=CurrentIndex2 && 'Table'[IF days]=0))
RETURN IF(ISBLANK(PreviousIndex), 0, (CurrentIndex2 - PreviousIndex))+1
Consecutive days = 
CALCULATE(MAX('Table'[Count days]),FILTER('Table','Table'[group]=EARLIER('Table'[group])))
Part = 
CALCULATE(MIN('Table'[Vacations Start Date]),FILTER('Table','Table'[group]=EARLIER('Table'[group])))

 

6.Here's my final result, which I hope meets your requirements.

vlinyulumsft_2-1719461818757.png

It may be noted that November 27 in your case is not consecutive from the previous date, so the expected output result you provided may be wrong in my understanding of your requirements.

 

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

HI,@MichelleRA_24 

Thank you for your quick reply.

1.The following is my updated calculation column, the rest remains unchanged:

IF days = 
VAR currentday1=[Vacations Start Date]
VAR predate=CALCULATE(MAX('Table'[Vacations Start Date]),FILTER('Table','Table'[Vacations Start Date]<currentday1))
RETURN IF(NETWORKDAYS(predate,currentday1)=2,1,0)

2.Here's my final result, which I hope meets your requirements

vlinyulumsft_0-1719554794879.png

3.Here are my related documents, I hope to help you:

NETWORKDAYS function (DAX) - DAX | Microsoft Learn

 

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

4 REPLIES 4
v-linyulu-msft
Community Support
Community Support

HI,@MichelleRA_24 

Regarding the issue you raised, my solution is as follows:

1. I have created the following table and the column names and data are the data you have given:

vlinyulumsft_0-1719461644560.png

2.First, we need to add a sequence to the powerquery:

vlinyulumsft_1-1719461662710.png

3.Secondly, use the following calculation column to determine whether it is continuous:

 

IF days = 
VAR currentday1=[Vacations Start Date]
VAR predate=CALCULATE(MAX('Table'[Vacations Start Date]),FILTER('Table','Table'[Vacations Start Date]<currentday1))
RETURN IF(predate+1=currentday1,1,0)

 

4.Then, relying on the previous calculation column, the grouping column is generated:

 

group = 
VAR CurrentIndex1 = [Index]
VAR PreviousIndex1= CALCULATE(MAX('Table'[Index]), FILTER('Table', 'Table'[Index]<=CurrentIndex1 && 'Table'[IF days]=0))
RETURN PreviousIndex1

 

5.You can then proceed to create calculation columns that meet your needs:

 

RETURN = 'Table'[Vacations Start Date]+1
Count days = 
VAR CurrentIndex2 = [Index]
VAR PreviousIndex = CALCULATE(MAX('Table'[Index]), FILTER('Table', 'Table'[Index]<=CurrentIndex2 && 'Table'[IF days]=0))
RETURN IF(ISBLANK(PreviousIndex), 0, (CurrentIndex2 - PreviousIndex))+1
Consecutive days = 
CALCULATE(MAX('Table'[Count days]),FILTER('Table','Table'[group]=EARLIER('Table'[group])))
Part = 
CALCULATE(MIN('Table'[Vacations Start Date]),FILTER('Table','Table'[group]=EARLIER('Table'[group])))

 

6.Here's my final result, which I hope meets your requirements.

vlinyulumsft_2-1719461818757.png

It may be noted that November 27 in your case is not consecutive from the previous date, so the expected output result you provided may be wrong in my understanding of your requirements.

 

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

 

 

 

Hi Leroy!

Your solution is very good, I´m impressed, thank you very much for dedicating that time. Regarding what you mentioned about November 27, it is correct to count Monday the 27th as consecutive from Friday, as weekends should not be counted as part of consecutive days. That's why the employee took 6 consecutive days despite having a weekend in between. Can this be corrected in the formula?

HI,@MichelleRA_24 

Thank you for your quick reply.

1.The following is my updated calculation column, the rest remains unchanged:

IF days = 
VAR currentday1=[Vacations Start Date]
VAR predate=CALCULATE(MAX('Table'[Vacations Start Date]),FILTER('Table','Table'[Vacations Start Date]<currentday1))
RETURN IF(NETWORKDAYS(predate,currentday1)=2,1,0)

2.Here's my final result, which I hope meets your requirements

vlinyulumsft_0-1719554794879.png

3.Here are my related documents, I hope to help you:

NETWORKDAYS function (DAX) - DAX | Microsoft Learn

 

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

 

Thanks for your time and support.👍

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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