Forum Discussion
Returning results with a unique condition
Hello all,
On a second sheet I'm looking to extract only the rows where a USER ID has ONLY ONE "ANI" status, in this case the only rows that meet that criteria are for "Raj Singh" and "Mr Goerge"
USER ID | NAME | STATUS |
11 | Jane Smith | ANI |
11 | John Smith | ANI |
15 | Raj Singh | ANI |
17 | Debbie Downer | NIN |
17 | Donald Downer | ANI |
21 | Lee Nguyen | ANI |
21 | Chun Lee Nguyen | ANI |
22 | Fransisco Galvez | NIN |
22 | Franchesca Galvez | ANI |
25 | Mr George | ANI |
I have attached the sample workbook, a little help please?
9 Replies
- ElElyonCopper Contributor
shade206 Your criteria may have been conveyed incorrectly, as in the case below, the rows that meets the criteria.
Criteria 1.
- the rows where a USER ID has ONLY ONE "ANI" status is as shown below;
USER ID NAME STATUS
15 Raj Singh ANI 17 Donald Downer ANI 22 Franchesca Galvez ANI 25 Mr George ANI Maybe the criteria you meant is as below
Criteria 2.
- User ID that appears once AND that has ONLY ONE "ANI" status.
if this is the criteria then you will only return the rows as shown below
USER ID NAME STATUS
15 Raj Singh ANI 25 Mr George ANI See the attached
I have added 2 new sheet(Criteria 1 and Criteria 2) that gives you both results. I designed it using Power Query advance Group By function, for every change you make to Sheet1 you need to click Refresh to have it reflected to Criteria 1 and Criteria 2 sheets.
- ElElyonCopper Contributor
I am glad it solved your problem. I will share the code below, if it still does not make sense.
Let me know, which of the criteria you wanted. And I could look into doing a quick video for you.
for Criteria 1 see the m code below.
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"USER ID", Int64.Type}, {"NAME", type text}, {"STATUS", type text}}), #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([STATUS] = "ANI")), #"Grouped Rows" = Table.Group(#"Filtered Rows", {"USER ID"}, {{"Count", each Table.RowCount(_), type number}, {"New", each _, type table [USER ID=number, NAME=text, STATUS=text]}}), #"Filtered Rows1" = Table.SelectRows(#"Grouped Rows", each ([Count] = 1)), #"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows1",{"New"}), #"Expanded New" = Table.ExpandTableColumn(#"Removed Other Columns", "New", {"USER ID", "NAME", "STATUS"}, {"USER ID", "NAME", "STATUS"}) in #"Expanded New"
For the Criteria 2 see the m code below.
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"USER ID", Int64.Type}, {"NAME", type text}, {"STATUS", type text}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"USER ID"}, {{"Count", each Table.RowCount(_), type number}, {"New", each _, type table [USER ID=number, NAME=text, STATUS=text]}}), #"Filtered Rows1" = Table.SelectRows(#"Grouped Rows", each ([Count] = 1)), #"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows1",{"New"}), #"Expanded New" = Table.ExpandTableColumn(#"Removed Other Columns", "New", {"USER ID", "NAME", "STATUS"}, {"USER ID", "NAME", "STATUS"}) in #"Expanded New"
Cheers!
- peteryac60Iron Contributor
- shade206Brass Contributor
That is CORRECT. However, i want ONLY the USER IDs that ONLY have ONE ANI peteryac60