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
RichOB
Post Patron
Post Patron

Need help with day count please

I have a dog shelter and I need to count the days that each kennel is empty. Each row is the duration that a dog is in a kennel.

 

I need the difference between the end date of a dog leaving the kennel and the start date of the next dog joining. If there is no start date of the next dog joining, I need Today's date to be calculated for the day count please.

 

For example, using the table below:

Kennel 1 = 0 days

Kennel 2 = 285 days

Kennel 3 = 186 days 

Kennel 4 = 0 days

 

KennelDogStart DateEnd Date 
1Max24/02/202404/03/2024
1Charles04/03/202425/07/2024
1Lila25/07/2024 
2Milo01/06/202426/08/2024
3Rex08/09/202410/10/2024
4Birdie01/11/202430/12/2024
4Bob30/12/2024 

 

Thanks

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Can I borrow your calendar for a minute?  I would like some extra days...

lbendlin_0-1741889242151.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XY69CoQwEIRf5Ugd2J+op+1deza2YhG5gIGAoI2P78agEmEJzMy3k+17RUqr1m7ycgHIwMiFCBRhkhh0or6TXYJb81DWSsB3Tv58sHmi1etIOf7mwxxLCLC6SirA+i4xYnUuHiUuNidFCDIXFa2PX/7epTqiEzQC8gOcxzw4Thp2", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Kennel = _t, Dog = _t, #"Start Date" = _t, #"End Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Start Date", type date}, {"End Date", type date}},"en-GB"),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Start Date", Order.Descending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows", {"Kennel"}, {{"Rows", each _, type table [Kennel=nullable text, Dog=nullable text, Start Date=nullable date, #"End Date "=nullable date]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Kennel Empty Days", each Int64.From(if Table.RowCount([Rows])>1 then [Rows]{0}[Start Date] - [Rows]{1}[End Date] else Date.From(DateTime.LocalNow()) - [Rows]{0}[End Date]),Int64.Type),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Rows"})
in
    #"Removed Columns"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the entire Source step with your own source.

 

View solution in original post

2 REPLIES 2
v-menakakota
Community Support
Community Support

Hi @RichOB ,

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

lbendlin
Super User
Super User

Can I borrow your calendar for a minute?  I would like some extra days...

lbendlin_0-1741889242151.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XY69CoQwEIRf5Ugd2J+op+1deza2YhG5gIGAoI2P78agEmEJzMy3k+17RUqr1m7ycgHIwMiFCBRhkhh0or6TXYJb81DWSsB3Tv58sHmi1etIOf7mwxxLCLC6SirA+i4xYnUuHiUuNidFCDIXFa2PX/7epTqiEzQC8gOcxzw4Thp2", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Kennel = _t, Dog = _t, #"Start Date" = _t, #"End Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Start Date", type date}, {"End Date", type date}},"en-GB"),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Start Date", Order.Descending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows", {"Kennel"}, {{"Rows", each _, type table [Kennel=nullable text, Dog=nullable text, Start Date=nullable date, #"End Date "=nullable date]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Kennel Empty Days", each Int64.From(if Table.RowCount([Rows])>1 then [Rows]{0}[Start Date] - [Rows]{1}[End Date] else Date.From(DateTime.LocalNow()) - [Rows]{0}[End Date]),Int64.Type),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Rows"})
in
    #"Removed Columns"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the entire Source step with your own source.

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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