Extract records based on two criteria

basic101

New Member
Joined
Mar 10, 2019
Messages
1
Hello! im just newbie in excel my question is what formula do I need to get just subjects of all Basic and Common type.
My sample dataset;
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Type
[/TD]
[TD]Subject
[/TD]
[/TR]
[TR]
[TD]Basic
[/TD]
[TD]Subject 1
[/TD]
[/TR]
[TR]
[TD]Basic
[/TD]
[TD]Subject 3
[/TD]
[/TR]
[TR]
[TD]Common
[/TD]
[TD]Subject 2
[/TD]
[/TR]
[TR]
[TD]Core
[/TD]
[TD]Subject 1
[/TD]
[/TR]
[TR]
[TD]Common
[/TD]
[TD]Subject 3
[/TD]
[/TR]
[TR]
[TD]Core
[/TD]
[TD]Subject 1
[/TD]
[/TR]
</tbody>[/TABLE]












I want extracted records to be:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Basic
[/TD]
[TD]Subject 1
[/TD]
[/TR]
[TR]
[TD]Basic
[/TD]
[TD]Subject 3
[/TD]
[/TR]
[TR]
[TD]Common
[/TD]
[TD]Subject 2
[/TD]
[/TR]
[TR]
[TD]Common
[/TD]
[TD]Subject 3
[/TD]
[/TR]
</tbody>[/TABLE]

Thank you.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
with PowerQuery (Get&Transform)

[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#5B9BD5]Type[/td][td=bgcolor:#5B9BD5]Subject[/td][td][/td][td=bgcolor:#70AD47]Type[/td][td=bgcolor:#70AD47]Subject[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Basic[/td][td=bgcolor:#DDEBF7]Subject 1[/td][td][/td][td=bgcolor:#E2EFDA]Basic[/td][td=bgcolor:#E2EFDA]Subject 1[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Basic[/td][td]Subject 3[/td][td][/td][td]Basic[/td][td]Subject 3[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Common[/td][td=bgcolor:#DDEBF7]Subject 2[/td][td][/td][td=bgcolor:#E2EFDA]Common[/td][td=bgcolor:#E2EFDA]Subject 2[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Core[/td][td]Subject 1[/td][td][/td][td]Common[/td][td]Subject 3[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Common[/td][td=bgcolor:#DDEBF7]Subject 3[/td][td][/td][td=bgcolor:#E2EFDA]Core[/td][td=bgcolor:#E2EFDA]Subject 1[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Core[/td][td]Subject 1[/td][td][/td][td][/td][td][/td][/tr]
[/table]


Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"Type"}, {{"Count", each _, type table}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Subject", each List.Distinct(Table.Column([Count],"Subject"))),
    #"Expanded Subject" = Table.ExpandListColumn(#"Added Custom", "Subject")
in
    #"Expanded Subject"[/SIZE]

in a meantime you can filter Core ;)

Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"Type"}, {{"Count", each _, type table}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Subject", each List.Distinct(Table.Column([Count],"Subject"))),
    #"Expanded Subject" = Table.ExpandListColumn(#"Added Custom", "Subject"),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Subject", each ([Type] <> "Core"))
in
    #"Filtered Rows"[/SIZE]

[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#5B9BD5]Type[/td][td=bgcolor:#5B9BD5]Subject[/td][td][/td][td=bgcolor:#70AD47]Type[/td][td=bgcolor:#70AD47]Subject[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Basic[/td][td=bgcolor:#DDEBF7]Subject 1[/td][td][/td][td=bgcolor:#E2EFDA]Basic[/td][td=bgcolor:#E2EFDA]Subject 1[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Basic[/td][td]Subject 3[/td][td][/td][td]Basic[/td][td]Subject 3[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Common[/td][td=bgcolor:#DDEBF7]Subject 2[/td][td][/td][td=bgcolor:#E2EFDA]Common[/td][td=bgcolor:#E2EFDA]Subject 2[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Core[/td][td]Subject 1[/td][td][/td][td]Common[/td][td]Subject 3[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Common[/td][td=bgcolor:#DDEBF7]Subject 3[/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td]Core[/td][td]Subject 1[/td][td][/td][td][/td][td][/td][/tr]
[/table]
 
Last edited:
Upvote 0
Welcome to the Board!


Excel Workbook
ABCDE
1TypeSubjectTypeSubject
2BasicSubject 1BasicSubject 1
3BasicSubject 3BasicSubject 3
4CommonSubject 2CommonSubject 2
5CoreSubject 1CommonSubject 3
6CommonSubject 3
7CoreSubject 1
8
9
10
sheet1


Array formulas
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself
 
Upvote 0
Or with a normal formula


Excel 2013/2016
ABCDE
1TypeSubjectTypeSubject
2BasicSubject 1BasicSubject 1
3BasicSubject 3BasicSubject 3
4CommonSubject 2CommonSubject 2
5CoreSubject 1CommonSubject 3
6CommonSubject 3
7CoreSubject 1
Template
Cell Formulas
RangeFormula
D2=IFERROR(INDEX(A$2:A$7,AGGREGATE(15,6,ROW($A$2:$A$7)-ROW($A$2)+1/($A$2:$A$7={"Basic","Common"}),ROWS($1:1))),"")
E2=IFERROR(INDEX(B$2:B$7,AGGREGATE(15,6,ROW($A$2:$A$7)-ROW($A$2)+1/($A$2:$A$7={"Basic","Common"}),ROWS($1:1))),"")
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

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