Count the bed filled on a given month/year

Zee996

New Member
Joined
Nov 30, 2021
Messages
30
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have Admission date and Discharge date. I am looking for a formula that will count the number of bed filled on the given month/year.

Here how the data looks like -
Admission DateDischarge Date
27-04-2022Still living on that bed
14-12-202213-02-2023
23-01-202320-02-2023
17-03-2023Still living on that bed

Looking for way to find the count by month and year -

JanFebMarAprilMay
2023Count of bedCount of bedCount of bedCount of bedCount of bed
2022Count of bedCount of bedCount of bedCount of bedCount of bed

Would it be helpful if anybody could help with formula.

Thank you.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
A Power Query Solution through today. Will update automatically if run daily.

Book1
ABC
2Admission DateDischarge Date
34/27/2022Still living on that bed
412/14/20222/13/2023
52/23/20222/20/2023
63/17/2023Still living on that bed
7
8YearMonth NameCount
92022April34
102022May62
112022June60
122022July62
132022August62
142022September60
152022October62
162022November60
172022December80
182023January93
192023February61
202023March46
212023April60
222023May62
232023June60
242023July62
252023August24
262022February6
272022March31
Sheet1


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Added Conditional Column" = Table.AddColumn(Source, "Custom", each if [Discharge Date] <> "Still living on that bed" then [Discharge Date] else DateTime.LocalNow()),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Conditional Column",{{"Custom", type date}, {"Admission Date", type date}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Discharge Date"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Discharge"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Dates", each List.Dates([Admission Date], Duration.Days([Discharge] -[Admission Date]) +1 ,#duration(1,0,0,0) )),
    #"Expanded Dates" = Table.ExpandListColumn(#"Added Custom", "Dates"),
    #"Inserted Year" = Table.AddColumn(#"Expanded Dates", "Year", each Date.Year([Dates]), Int64.Type),
    #"Inserted Month Name" = Table.AddColumn(#"Inserted Year", "Month Name", each Date.MonthName([Dates]), type text),
    #"Grouped Rows" = Table.Group(#"Inserted Month Name", {"Year", "Month Name"}, {{"Count", each Table.RowCount(_), Int64.Type}})
in
    #"Grouped Rows"
 
Upvote 0

Forum statistics

Threads
1,215,201
Messages
6,123,621
Members
449,109
Latest member
Sebas8956

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top