This can also be accomplished using Power Query, available in Windows Excel 2010+ and Excel 365 (Windows or Mac)
To use Power Query
- Select some cell in your Data Table
Data => Get&Transform => from Table/Range
or from within sheet
- When the PQ Editor opens:
Home => Advanced Editor
- Make note of the Table Name in Line 2
- Paste the M Code below in place of what you see
- Change the Table name in line 2 back to what was generated originally.
- Read the comments and explore the
Applied Steps
to understand the algorithm
let
//Change Name in next line to reflect actual data source
Source = Excel.CurrentWorkbook(){[Name="Table5"]}[Content],
//Set the data types
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Status", type text}, {"Name", type text}}),
//Group by status and Name with "GroupKind.Local" argument
#"Grouped Rows" = Table.Group(#"Changed Type", {"Status", "Name"}, {
{"Days", each Table.RowCount(_), Int64.Type},
{"Start Date", each List.Min([Date]), type nullable date},
{"End Date", each List.Max([Date]), type nullable date}},
GroupKind.Local),
//Select only "Paid Leave" in the Status column
#"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each ([Status] = "Paid Leave"))
in
#"Filtered Rows"

Note: Most of this can be done in the User Interface. However, the default type
for the Date
column needs to be changed from datetime
to date
, and the GroupKind.Local
argument needs to be added manually