简体   繁体   中英

How to grab the value of an excel column based on a unique value in another column

I have the following excel sheet and I'm trying to make a calculation that says how many of the courses are Live. I have duplicate course values in rows so I need a way to say distinct courses and grab the delivery method tied to it.

Course   Delivery_Method
16679    Live
16679    Live
16743    Live
16861    In-House

I'd like the output of the calculation to be:

Live Courses: 2

It may be important to note that 1 course will never have a live row and an in-house row. They will always be the same.

There is probably a much better way to do it, but this is a roundabout method I have used before.

It requires a second worksheet that does the calculations. We will call your current sheet 'Sheet 1' and the Calculating sheet 'Sheet 2'. I am also calling [Course] 'Col A' and [Delivery_Method] 'Col B'.

On Sheet 2, create these Columns:

A. [Course] Copy from 'Sheet 1' and paste to 'Sheet 2'

B. [Leave Blank] You will be creating a list in Column B that shows all items in Column A, but with no duplicates. If there is anything in Column B, Clear Contents (see why below). Select Col A. On the Data tab, select Advanced. Click 'Copy to another location', at 'Copy to:' enter '$B:$B' Click 'Unique records only'. Click 'OK'. Col B should now be populated.

Why you need to clear Col B: 1) The filter likes to drop the existing header in, so if that space is occupied, you'll get an error message; 2) if your new sorted list is shorter than your old sorted list, then you'll end up with extra fields at the bottom that are from your old list.

One more thing - If you ever use this feature again, you need to know that it can only be done within the same sheet. You can't use a 'Copy To' location that's on another sheet or document.

C. [Live] Enter this formula in all cells: =CountIfs([Sheet1!A:A,Bb2,'Sheet 1'!B:B,"Live")

D. [In-House] Enter this formula in all cells: =CountIfs([Sheet1!A:A,B2,'Sheet 1'!B:B,"In-House")

E. [Total Live] In row 2, enter: =Sum[$C:$C]

F. [Total In-House] In row 2, enter: =Sum[$D:$D]

You can also just do an auto-sum at the bottom of your [Live] and [In-House] Columns instead of using columns E and F.

Each time you do this, you should double-check the bottom of the list to be sure you have formulas to match all of the lines populated in Col B.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM