How do you count the numbers of members in my table?
The table is called Table2. I would like to see the amount of people that meet the criteria of having the membership code of A3 (changing when it moves down a cell) and pay by either Annual Membership 1, or Annual membership 2.
I can recommend three ways of going about this, in descending order of preference.
Use a pivot table to summarise the data into a cross table, if
there is a new type of payment code it automatically be reflected,
you don't need to do complex formulae, only make sure the input
range used for the pivot table includes all the data. You need to
manually refresh the Pivot table.
Use the sumifs() function (you can sum a cell with 1 as value),
research a bit on multiple conditions, there is plenty of info out
there (apparently sumifs() supports up to 29), I can suggest
this one
Sometimes I just use the formula =B1&"-"&C1&"-"D1 (into a fourth E
column) to combine the two or more cells I want to test into a
single text value and then do the countif() or sumif(). It is quick
and dirty but can be very easy to understand and has the benefit
that at each row you have some value you could filter for using the
data filter functionality. You can also use an OR() and IF() to
create the condition at each row that would yield "True" or other
value that is more meaningful (e.g.
If(And(A1="A3",Or(B1="Membership 1",B1="Membership
2")),"VIP","Regular"), then use the countif() at the bottom to count
the VIPs.
You can use also array formulas but I found them
difficult to maintain and I don't have enough real life experience
of using it.
Note: I didn't test the formulae, this is illustrative to give you a start, my advise is you use pivots if you only need a summary reporting.
Good luck!
Related
I think Excels FILTER function is great, especially when combined with SORT, CHOOSECOLS and so on.
What I did not even manage to google, let alone find a solution for is: can I "paste" a calculated columns to the results of FILTER function.
For example:
I have the original data on the left, I want to FILTER the rows where a person had passed a test and then for example COUNT how many times have they passed a test.
It is just an example, it can be how many exams have they took in the first trimester, analogously it could be the total amount billed if you look at customer invoices and so on.
The column with the yellow title is the column that I want "pasted", i.e. calculated.
I could do FILTER and then add formulas in the last column as I did here. But it does not adapt to number of rows being filtered, as below (if Carol passed one test less for example).
How to do it or is it for some reason better to do it fundamentally in another way?
If you have Excel 365 current channel you can use this formula:
=LET(d,A24:D35,
f,FILTER(d,INDEX(d,,4)=TRUE),
sPassed,CHOOSECOLS(f,1),
cnt,MAP(sPassed,LAMBDA(s,ROWS(FILTER(sPassed,sPassed=s)))),
HSTACK(f,cnt))
As COUNTIF doesn't work within MAP, you have to use the FILTER function together with ROWS to count how often a student has passed. .
The issue I am having is trying to use XLOOKUP on a table column that has been generated using a ranking formula.
The Rank column is created using the following formula so that it adjusts dynamically depending on the visible columns (auto-filtering) since RANK.AVG or EQ does not take that into account.
=SUMPRODUCT(SUBTOTAL(3,OFFSET(Table2[[#All],[Sales]],ROW(Table2[[#All],[Sales]])-MIN(ROW(Table2[[#All],[Sales]])),0,1)),--([#Sales]<Table2[[#All],[Sales]]))
The XLOOKUP I am using is simple
=XLOOKUP(1,Table2[Rank], Table2[Rep])
The idea is that the field at the top would show the top ranked performer based on the visible rows. The problem is that when filtering the data, the rank column adjusts as it should, but the XLOOKUP does not function as I would expect. It sticks with the originally ranked 1 or even does something complete weird that I can't explain when running combinations of filters in the region column..
Anyone have any advice how I could better structure this to make it function in the intended manner. Any help at all would be appreciated.
You'll need to employ a similar construction to account for visible rows only, for example:
=LOOKUP(1,QUOTIENT(0,SUBTOTAL(3,OFFSET(INDEX(Table2[Sales],1),ROW(Table2[Sales])-MIN(ROW(Table2[Sales])),))*(Table2[Rank]=1)),Table2[Rep])
Not sure why you're referencing the table header row in your other formula.
I have below an example pivot table with Countries as my columns, and Dates as my rows. The data for this pivot is based on A1:C13. Cells F1:G3 is what the user of this model can adjust. They can change the country and/or the date ranges.
What I am needing is a single formula to output the total of their selection. As my actual data set contains many countries, simply writing an nested IF statement won't suffice. The dataset also needs to be in pivot table - hence the GETPIVOTDATA requirement.
I've gotten about half of the way there using this formula here:
=SUM(GETPIVOTDATA("Sum of Value",$A$15,"Date",ROW(INDIRECT(F2&":"&F3)),"Country",F1:G1))
The problem here is that this formula is not dynamic for the differing date selections per country.
Can anyone assist?
You need a separate GETPIVOTDATA for each country:
=SUM(GETPIVOTDATA("Sum of Value",$A$15,"Date",ROW(INDIRECT(F2&":"&F3)),"Country",F1),GETPIVOTDATA("Sum of Value",$A$15,"Date",ROW(INDIRECT(G2&":"&G3)),"Country",G1))
The answer provided by #basic is the closest one for the original question, i.e. using GETPIVOTDATA to work out the total per given parameters.
If the calculation can be done on the original data table (Range A1:C13), then here is another solution to calculate the total.
=SUMPRODUCT((A2:A13=F1:G1)*(B2:B13>=F2:G2)*(B2:B13<=F3:G3)*(C2:C13))
In order to make the above calculation "dynamic", i.e. the calculation updates as the rows expands in the table, you can put the source data into a Structured Reference Table, give a Name to each column, such as "List_Ctry" for Column A, "List_Date" for Column B, and "List_Value" for Column C, then the range behind each name will update automatically when the source data changes. Using these names, the formula will be something like:
=SUMPRODUCT((List_Ctry=F1:G1)*(List_Date>=F2:G2)*(List_Date<=F3:G3)*List_Value)
You can also give names to the three parameters, being the range of country, range of start date, and range of end date. I will not illustrate further as if you understand the above concepts, you should be able to do this step yourself.
By using Name in the excel workbook, it will enable you to refer to the source data conveniently without the need to lay it out in your final report, so I do not understand what is the limitation here to stop you from calculating from the source data but have to work on the pivot table, as the calculations on pivot table are limited and not that intuitive.
Feel free to let me know if you have any questions :)
I'm having an issue with some data that I'm working on that has had me stuck for a while.
I'm working on some patient data for a clinical practice that has each patient encounter logged on a separate line with an account ID, date of service, the height and weight measurements for that date, and other variables.
Aside from VLOOKUP and the usual formulae/functions I've got a pretty rudimentary understanding of Excel but I can pick up on things fairly quickly.
In the data I've got each line tied to a patient account ID as well as what quarter the DOS was in. For patients with multiple visits, they will be identifiable by repetitions of the account ID number on other lines.
For some patients, there will also be repetitions in the quarter if the same patient was seen twice in the same quarter. This is where I need help.
I'd simply like to average the value of a variable for each patient in each quarter. I'm not sure if AVERAGEIFS is the right function to use but I need an operation that checks for matches in a line of both account ID and quarter (Q1, Q2, Q3, or Q4) with the other lines in the sheet and comes up with a quarterly average for the variables in question.
What I have
What I need
If I'm understanding your question, you could use AVERAGEIFS to accomplish what you are asking. With excel, a lot of how successful an approach will be is determined by how your data is structured, and if/how often you are planning on updating your work.
It would be easier to give a concrete answer with an example of the data you are looking at.
If your source data is in columns A:D something like:
and you are looking to summarize the weight data in I by account ID and Quarter:
you could use AVERAGEIFS(C:C,A:A,G2,B:B,H2) this would find the cells in column A that match the value in G2, find the cells in column B that match the value in H2, and report the mean value in column C of the matching rows.
An alternative is to use a pivot table, which automates a lot of what you are trying to do. For that approach you would select your data block, and click on Insert>>Insert Pivot Table (at least in my version). That should bring up a wizard. Accepting the defaults will create a new sheet. Then look on the right side of your window, and you should see a list of your column names near the top, and four boxes called Filters, Columns, Rows, and Values. You should be able to drag and drop your columns into these boxes to get summaries of your data. If you add your Account ID and Quarter tabs as columns, and your height and weight as Values, then right click on each of the value columns and select "Value Field Settings" and select Average from the menu that pops up. That should give you something that looks like:
At that point, you can change the formatting to make if fit your needs, or copy data somewhere else.
The AVERAGEIFS approach will automatically update if you add more data, but will only summarize things that match the values you list. If there is an account ID/Quarter pair that isn't in the summary column you won't have any idea it's there. If you are summarizing an ID/Quarter pair that isn't in your data you'll end up with a division by Zero error like in the example.
The Pivot Table option only updates when you manually click refresh (right click and choose refresh pivot table from the menu), but will summarize all the data based on the columns you've selected. It's also a little more robust as you avoid having to type out the formulas and make sure you are pointing to the right column. This option also by default provides nested summaries; you can turn the subtotals and grand totals off if you want.
I used the function:
=SUMPRODUCT(($B$2:$B$13="Customer 1")*($C$2:$C$13="Q1"))
Where Customer 1 could be a user id and Q1 you can change to which quarter you want.
Excel screenshot
I have column A for Job Type.
I have column B for Experience Range.
I have column C for salary.
These are in a sheet named 'Data'.
I have created a pivot table with Job Type as rows and Experience Range as columns. (in another sheet)
I want to find median for each cell in the Pivot Table.
How do I do that?
e.g. how do I find the median of Salary for all 'Stage Manager' (cell A2) with 'less than 2 years' (cell B1) experience?
Please help. Thank you!
As you've no doubt discovered, the median isn't listed on the grouping options (sum, min, max, count, etc).
There doesn't appear to be a direct way around the problem; however, you may be able to hack your way around it by adding custom a formula inside the table. Then use the median() function in the formula.
Another approach is abandon pivot tables and use array formulas instead.
You can use * for and and + for or. FALSE is coded as 0 and TRUE as 1.
0*1 = 1, so if only one condition is met it will be FALSE(AND)
1+0 or 1+1 is >0, so if only one condition is met, it will still be >0 (OR)
You can use this fact to do a test as to whether your condition is >0 and then transform your array, so that if the condition is true, the array is the array but otherwise it equal . This will basically eliminate all rows where the conditions are not met (making them count as blank in any array formula)
You can use this tick for a large number of AND and OR conditions.
If you use name manager to name your arrays, then you can very easily vary conditions very fast and create a simulated pivot table.
You can then use the aggregate function to ignore hidden rows (e.g. aggregate can calculate median, percentiles and other stuff), and then the filter function can effectively work as a pivot filter.
I usually make my first column a test column that tests if a row is hidden or not and returns 1 if visible and 0 otherwise. Then I build that condition into my condition stack to act as an additional AND switch. This means suddenly your formulas react to the filter to only consider values that are filtered in.
This stuff is really great to do multi-conditional calculations on a large amount of data without the need to manually calculate after each filter - the calculations happen on the fly, as you filter!
Calculations can take 3-5 seconds depending on how many conditions you have and the size of your raw data, so not quite as fast as a pivot table, but very convenient.