Pivot table to find number that is the intersection of set theory

rbbastos

New Member
Joined
Apr 17, 2020
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
Hello Everyone,

I am facing a challenging situation in Excel.
Please visualize the below table. I was wondering if it is possible to create a pivot table that count not only 2019 and 2020 number of interviews. My idea is to make the pivot table to count also the number of person that were interviewed both 2019 AND 2020 (in my example 3). I would love to have it automated since the real spreadsheet has more than 300 rows and it keep increasing.
I am very thankful for any tip on how to solve this challenge. It can even be a formula separated from the pivot table.

Thank you in advance,


Capture.PNG
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Just create a new column using OR based on the inteviewed column then pivot on that eg

=IF(OR(B2=2019,B2=2020),"19-20","Something else")
 
Upvote 0
Hi Steve,

Thanks for the quick reply.
The formula you recommended returned true ("19-20") for every evaluation. I believe it is checking only column B. It will return "Something else" only if I include a year different then 2019 and 2020.
I believe we need something that check 2019 and 2020 only if the name appear more then once.

Rbb
 
Upvote 0
Hi Steve,

Thanks for the quick reply.
The formula you recommended returned true ("19-20") for every evaluation. I believe it is checking only column B. It will return "Something else" only if I include a year different then 2019 and 2020.
I believe we need something that check 2019 and 2020 only if the name appear more then once.

Rbb

I pasted an image of what I am saying to help the understanding. I included some more fake data to show that, even though, "Daniel P. Reese" show up twice, he is not supposed to be counted since he was interviewed 2018-2019 and I want only 2019-2020.

The number 3 that I am trying to include in the pivot table means that I have 3 people (Carla, Catrina and John) that were interviewed both 2019-2020.

Hope this help better.

1587169842243.png
 
Upvote 0
Maybe this option
VBA Code:
Sub MM1()
Dim lr As Long, r As Long, n As Integer
lr = Cells(Rows.Count, "A").End(xlUp).Row
n = 0
For r = lr To 2 Step -1
    If Cells(r, 1).Value = Cells(r - 1, 1).Value And Cells(r, 2).Value = "2020" And Cells(r - 1, 2).Value = "2019" Then
        n = n + 1
    End If
Next r
Cells(6, "D").Value = "2019/2020"
Cells(6, "E").Value = n
End Sub
 
Upvote 0
Maybe this option
VBA Code:
Sub MM1()
Dim lr As Long, r As Long, n As Integer
lr = Cells(Rows.Count, "A").End(xlUp).Row
n = 0
For r = lr To 2 Step -1
    If Cells(r, 1).Value = Cells(r - 1, 1).Value And Cells(r, 2).Value = "2020" And Cells(r - 1, 2).Value = "2019" Then
        n = n + 1
    End If
Next r
Cells(6, "D").Value = "2019/2020"
Cells(6, "E").Value = n
End Sub


Thanks Michael. That worked. I saved the VBA snipet using a PivotTableUpdate event and now as soon as I refresh the Pivot table it runs the vba code and check if the number is correct.
 
Upvote 0
I guess taking it a step further, you could ask the user for the start and end year via inputBoxes !!
 
Upvote 0

Forum statistics

Threads
1,216,000
Messages
6,128,204
Members
449,435
Latest member
Jahmia0616

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