Table:
0
A
B
C
D
E
F
1
District
Incumbent
Party
First elected
Result
Candidates
2
Virginia 2
David Holmes
Democratic-Republican
1797
Re-elected
David Holmes (DR) Alexander Sinclair (F)
3
Virginia 4
Abram Trigg
Democratic-Republican
1797
Re-elected
Abram Trigg (DR)
4
Virginia 5
John J. Trigg
Democratic-Republican
1797
Re-elected
John J. Trigg (DR)
5
Virginia 6
Matthew Clay
Democratic-Republican
1797
Re-elected
Matthew Clay (DR)
6
Virginia 7
John Randolph
Democratic-Republican
1799
Re-elected
John Randolph (DR)
7
Virginia 8
Samuel Goode
Federalist
1799
Democratic-Republican gain
Thomas Claiborne (DR)
8
Virginia 9
Joseph Eggleston
Democratic-Republican
1798 (special)
Democratic-Republican hold
William B. Giles (DR)
9
Virginia 10
Edwin Gray
Democratic-Republican
1799
Re-elected
Edwin Gray (DR) Nicholas Faulcon (DR)
10
Virginia 12
Thomas Evans
Federalist
1797
Retired Federalist hold
John Stratton (F) John Page (DR)
11
Virginia 13
Littleton Waller Tazewell
Democratic-Republican
1800 (special)
Retired Democratic-Republican hold
John Clopton (DR) Samuel Tyler (DR)
12
Virginia 14
Samuel J. Cabell
Democratic-Republican
1795
Re-elected
Samuel J. Cabell (DR)
13
Virginia 15
John Dawson
Democratic-Republican
1797
Re-elected
John Dawson (DR)
14
Virginia 18
John Nicholas
Democratic-Republican
1793
Retired Democratic-Republican hold
Philip R. Thompson (DR) John Blackwell (F)

Questions and formulas:
Question: What party did the incumbent from the Virginia 5 district who was re-elected and was first elected in 1797 belong to?
Formula: UNIQUE(CHOOSECOLS(FILTER(A1:F1,(E1="Re-elected")*(D1=1797)*(A1="Virginia 5")),3))
Formula2: UNIQUE(CHOOSECOLS(FILTER(A2:F14,(E2:E14="Re-elected")*(D2:D14=1797)*(A2:A14="Virginia 5")),3))
Level: medium
Question: When was the incumbent first elected in the district where the result was a democratic-republican gain? 
Formula: UNIQUE(CHOOSECOLS(FILTER(A1:F1,E1="Democratic-Republican gain"),4))
Formula2: UNIQUE(CHOOSECOLS(FILTER(A2:F14,E2:E14="Democratic-Republican gain"),4))
Level: medium
Question: In what district was the incumbent Edwin Gray? 
Formula: UNIQUE(CHOOSECOLS(FILTER(A1:F1,B1="Edwin Gray"),1))
Formula2: UNIQUE(CHOOSECOLS(FILTER(A2:F14,B2:B14="Edwin Gray"),1))
Level: medium
Question: When was the incumbent from the Virginia 10 district first elected? 
Formula: UNIQUE(CHOOSECOLS(FILTER(A1:F1,A1="Virginia 10"),4))
Formula2: UNIQUE(CHOOSECOLS(FILTER(A2:F14,A2:A14="Virginia 10"),4))
Level: medium