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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
BlueBird
Frequent Visitor

Counting consecutive dates

Need to count consecutive dates between a date range per person. the columns are: signature date, admit date, discharge date, person id. want to count consecutive signature dates between admit date and discharge date per person id. when person id changes start count over.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @BlueBird ,

 

I tried creating the sample data based on your description.

vstephenmsft_0-1699598796859.png

Here's my solution.

1.Group by person id column.

vstephenmsft_1-1699598841175.png

Select All Rows.

vstephenmsft_2-1699598922324.png

vstephenmsft_3-1699598926656.png

2.Add an index column.

vstephenmsft_4-1699598984074.pngvstephenmsft_5-1699598994428.png

3.Expand it.

vstephenmsft_6-1699599252101.pngvstephenmsft_7-1699599258551.png

4.And the index column is counting consecutive dates. You can rename it.

vstephenmsft_8-1699599319810.png

 

Best Regards,

Stephen Tao

 

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

9 REPLIES 9
Syndicate_Admin
Administrator
Administrator

Hope this helps!

 

Set(currentCount, 0);
Set(previousPersonId, Blank());

ForAll(
SortByColumns(YourDataSource, "PersonId", "SignatureDate"), // Replace with your data source
If(
ThisRecord.PersonId <> previousPersonId,
Set(currentCount, 0)
);

If(
DateDiff(previousRecord.SignatureDate, ThisRecord.SignatureDate, Days) = 1,
Set(currentCount, currentCount + 1),
Set(currentCount, 1)
);

// Your additional logic using the currentCount

Set(previousPersonId, ThisRecord.PersonId)
)

Anonymous
Not applicable

Hi @BlueBird ,

 

I tried creating the sample data based on your description.

vstephenmsft_0-1699598796859.png

Here's my solution.

1.Group by person id column.

vstephenmsft_1-1699598841175.png

Select All Rows.

vstephenmsft_2-1699598922324.png

vstephenmsft_3-1699598926656.png

2.Add an index column.

vstephenmsft_4-1699598984074.pngvstephenmsft_5-1699598994428.png

3.Expand it.

vstephenmsft_6-1699599252101.pngvstephenmsft_7-1699599258551.png

4.And the index column is counting consecutive dates. You can rename it.

vstephenmsft_8-1699599319810.png

 

Best Regards,

Stephen Tao

 

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

 

Anonymous
Not applicable

Ok so in that case we really don't need the admit and discharge date. We can just group by the person id and the signature date, and add the GroupKind.Local parameter to your formula, right before the closing parentheses in your Table.GroupBy function. This will group all person ids with contiguous dates. Use the "All Rows" aggregation if you want to keep your other columns, or just use min/ max on the admit/discharge.

 

--Nate 

Unfortunately I do need admit and discharge date - -I want to count the consecutive dates  - - comparing date to the previous date. admit and discharge date plays a role since someone could have multiple admin and discharge date.

 

Anonymous
Not applicable

= Table.AddColumn(PriorStepOrTableName, "Count", each Duration.Days([Discharge Date] - [Admit Date]), Int64.Tyoe)

 

--Nate

Thank you Nate. I tried using your answer and it did not work.

Thank you for your response. I am actually looking for the number of consecutive signature dates between the admit date and discharge date per person id.

 

For example, if person id 1234 was admitted on 11/01/2023 and discharged on 11/05/2023 and signed a document on 11/01/2023, then another document on 11/02/2023 and another document on 11/05/2023. The answer would be 2 consecutive dates. the document on 11/05/2023 would not count. Also, when the person id changes the counts starts over.  I hope that makes sense.

 

I hope someone can help me with coming up with solution.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.