Forum Discussion
If 2nd Date/Time Row, Remove Both
I'm pulling data from SQL for facility check-ins. I want only a list of people who are still in the building. In the attached screen shot, stationid 52 is a check-in station and stationid 192 is a check-out station. If memid has an entry for the stationid 192 check-out staion, I want to filter out both rows for stationid 52 and stationid 192, leaving only the rows for memid who have checked-in and no rows for memid who have checked-out. You can see in this screen shot that memid 98033 has a row for both stationid 52 and 192. I want both rows for memid 98033 filtered out.
28 Replies
- edhansCommunity Champion
This is certianly doable in Power Query, but can you provide data?
How to get good help fast. Help us help you.
How to Get Your Question Answered Quickly
How to provide sample data in the Power BI Forum- AnonymousNot applicable
I keep getting "invalid HTML" errors on the headings when I try to paste the data into the table.
- edhansCommunity Champion
did you follow the directions in the links I provided, repeated below? The Table feasure can be finicky in the forum
How to get good help fast. Help us help you.
How to Get Your Question Answered Quickly
How to provide sample data in the Power BI Forum
- AnonymousNot applicable
OK, I typed the relevent columns directly into Excel and pasted that here...
chkinid memid checkin stationid 5438177 98033 5/21/2020 2:17:49 PM 52 5438178 130732 5/21/2020 2:17:56 PM 52 5438179 134806 5/21/2020 2:18:06 PM 52 5438180 76795 5/21/2020 2:18:14 PM 52 5438181 103055 5/21/2020 2:18:20 PM 52 5438182 97640 5/21/2020 2:18:26 PM 52 5438183 113062 5/21/2020 2:18:35 PM 52 5438184 98033 5/21/2020 2:49:17 PM 192 - edhansCommunity Champion
Is this what you need?
I didn't actually compare the station IDs. I just removed them if there were more than one present
You might want to add additional Group By columns (Days, employee codes or whatever) if your data is a bit more complex. See the M code below.
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Donelet Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dZBLCsMwDAWvErwORF9L8h0K3Yfc/xqRU7qp1ZXgMYOkd55NhR3N2t7CgTmnHoQHAcFGA21IbO/XjKld+5f3DJDBmFZBeyHEI4hD/xV8QCE4ZGDdQlcepeBxLgAGLYScqzAvD+sCBV8dNKvB/LkvL/tgLQT506lEtvThMVK4bg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [chkinid = _t, memid = _t, checkin = _t, stationid = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"chkinid", Int64.Type}, {"memid", Int64.Type}, {"checkin", type datetime}, {"stationid", Int64.Type}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"memid"}, {{"All Rows", each _, type table [chkinid=number, memid=number, checkin=datetime, stationid=number]}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Keep", each Table.RowCount([All Rows]) < 2, type logical), #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Keep] = true)), #"Expanded All Rows" = Table.ExpandTableColumn(#"Filtered Rows", "All Rows", {"chkinid", "checkin", "stationid"}, {"chkinid", "checkin", "stationid"}), #"Removed Other Columns" = Table.SelectColumns(#"Expanded All Rows",{"checkin", "memid", "chkinid", "stationid"}) in #"Removed Other Columns"