Convert a SUMIFS to SUBTOTAL across two tables in Excel - excel-formula

I have been creating a home budget file in Excel but have hit a snag in one of my formulas and am hoping someone can help me solve this. I have seen a couple of answers on this forum, but have had no luck in incorporating the answers into my spreadsheet.
I have two tables, on separate Sheets and need to access the values from one table in another table:
Sheet(1) has the table named INCDATA
Sheet(2) has the table named IEINC
Table IEINC has the source (search) criteria to look for in table INCDATA.
I have the following formula that correctly sums the data between the two tables;
=SUMIFS(INDEX(INCDATA,,MATCH(C$10,INCDATA[#Headers],0)),INCDATA[[Details]:[Details]],$B11)
What I am now trying to do is to either add this to, or change this to a "SUBTOTAL" function so that only visible rows are calculated when I filter the dates in table INCDATA
I have tried this formula, but get the wrong result;
=SUBTOTAL(109,INDEX(INCDATA,,MATCH(C$10,INCDATA[#Headers],0)),INCDATA[[Details]:[Details]],$B11)
That formula results in a Total of all Values displayed:
60.00 (Displayed in each row of the search criteria)
But what I am looking to do is add and display the individual search criterias based on the displayed rows when filtered.
Income01 10.00
Income02 20.00
Income03 30.00
Does anyone have any suggestions.

Maybe this is what your are looking for.
Change in Subtotal from 109 to 9.
=SUBTOTAL(9, ....
Function of Subtotal:
"Function_num Required. The number 1-11 or 101-111 that specifies the function to use for the subtotal. 1-11 includes manually-hidden (filtred) rows, while 101-111 excludes them (hidden/filtered rows); filtered-out cells are always excluded."
So converting this formula to take care of filtering it should go from:
=SUMIFS(INDEX(INCDATA,,MATCH(C$10,INCDATA[#Headers],0)),INCDATA[[Details]:[Details]],$B11)
to this, applied in Sheet "Income&Expenses" Cell: H11
=SUMPRODUCT(SUBTOTAL(9, OFFSET('Income(Data)'!$C$5:$C$10,ROW('Income(Data)'!$C$5:C9)-MIN(ROW('Income(Data)'!$C$5:C9)),,1)),--('Income(Data)'!$B$5:B9=$B$11))
So when you apply filter on the sheet "Income(Data)":
It will only sum the applied filters in the "Income&Expenses":

Related

Excel count Unique ID's between two dates + a distinct count of another column for each ID

I am struggling with an Excel formula. I am trying to count the number of Unique ID's between two dates (I have that formula working), but I also want to count the SignUpRoles for each unique ID that qualified between the two dates. I am using O365.
Here is how I am capturing the UserId counts in K10:14
=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=K5,IF(Weartime13[RecordDate]<=J5,MATCH(Weartime13[UserId],Weartime13[UserId],0))),ROW(Weartime13[UserId])-ROW(A5)+1),1))
Here is the worksheet I am working with: RDS_Report
Screenshot:
RDS Report Screenshot
So what I mean by adding another 'if' is that in L14 (for example) you would have
=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=O5,IF(Weartime13[RecordDate]<=J5,IF(Weartime13[SignUpRole]=L9,MATCH(Weartime13[UserId],Weartime13[UserId],0)))),ROW(Weartime13[UserId])-ROW(A5)+1),1))
and in the next column that would change to M9 and N9:
=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=O5,IF(Weartime13[RecordDate]<=J5,IF(Weartime13[SignUpRole]=M9,MATCH(Weartime13[UserId],Weartime13[UserId],0)))),ROW(Weartime13[UserId])-ROW(A5)+1),1))
=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=O5,IF(Weartime13[RecordDate]<=J5,IF(Weartime13[SignUpRole]=N9,MATCH(Weartime13[UserId],Weartime13[UserId],0)))),ROW(Weartime13[UserId])-ROW(A5)+1),1))
I've filled in the last row:
EDIT
As noted by #JosWoolley, a structured reference would have been preferable to row(A5). I would suggest:
=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=O5,IF(Weartime13[RecordDate]<=J5,IF(Weartime13[SignUpRole]=L9,MATCH(Weartime13[UserId],Weartime13[UserId],0)))),ROW(Weartime13[UserId])-ROW(Weartime13[#Headers])),1))
But what if you want to pull these formulas across so that L9 changes automatically to M9 and N9 but it still references the same table columns? I had to look this one up and the answer is:
=SUM(IF(FREQUENCY(IF(Weartime13[[RecordDate]:[RecordDate]]>=$O5,IF(Weartime13[[RecordDate]:[RecordDate]]<=$J5,IF(Weartime13[[SignUpRole]:[SignUpRole]]=L9,MATCH(Weartime13[[UserId]:[UserId]],Weartime13[[UserId]:[UserId]],0)))),ROW(Weartime13[[UserId]:[UserId]])-ROW(Weartime13[#Headers])),1))
Formula for the last row using count & filter would be
=COUNT(UNIQUE(FILTER(Weartime13[UserId],(Weartime13[RecordDate]<=J5)*(Weartime13[RecordDate]>=O5))))
for the total and
=COUNT(UNIQUE(FILTER(Weartime13[[UserId]:[UserId]],(Weartime13[[RecordDate]:[RecordDate]]<=$J5)*(Weartime13[[RecordDate]:[RecordDate]]>=$O5)*(Weartime13[[SignUpRole]:[SignUpRole]]=L9))))
pulled across for the SignUpRole breakdown, assuming UserId is numeric.
But what if you wanted a single formula that could be pulled both down and across for the whole range of dates and roles? This could be arranged as follows:
=COUNT(UNIQUE(FILTER(Weartime13[UserId],(Weartime13[RecordDate]<=J$5)*(Weartime13[RecordDate]>=INDEX($K$5:$O$5,ROW()-ROW($9:$9))))))
for the total and
=COUNT(UNIQUE(FILTER(Weartime13[[UserId]:[UserId]],(Weartime13[[RecordDate]:[RecordDate]]<=$J$5)*(Weartime13[[RecordDate]:[RecordDate]]>=INDEX($K$5:$O$5,ROW()-ROW($9:$9)))*(Weartime13[[SignUpRole]:[SignUpRole]]=L$9))))
for the role columns.
Is there a simpler way of doing this whole thing? Maybe with pivot tables or perhaps power query, but that would be a separate answer :-)

How can I create a table in Excel from a spreadsheet that contains data that is grouped in rows

I have a thousands of rows of here data in a spreadsheet (excel 1 image) that I need to create a table with the data populated across the headers below.
If you don't want to use a VBA or spend time with other custom queries, you can do something like this (not, need to create helper column):
Create a helper column that does a count if:
Using this formula:
=IF(B2="Facility ID:", COUNTIFS($B$1:B2,"Facility ID:"),"")
Then structure your data table like this:
And you can use this formula (starting in cell I7):
=INDEX($A:$E,MATCH($H7,$A:$A,0)+I$4,I$5)
Then all you need to do is drag down the rows and increment the counts and it should work provided that the spacings always stay the same and the locations of the fields also stay the same
This solution requires a version of Excel that supports XLOOKUP and Dynamic Arrays.
I would add two columns. One to count records and one to count the line number of the record like so.
E2 is =IF(A2="Facility ID:",MAX(E1:$E$1)+1,E1) and F2 is =IF(E2=E1,F1+1,1). Those formulas are dragged all the way down with the exception of the last row. That is a 6 manually entered because the typical 4th and 5th line are missing from that record.
Then sheet2 looks like this.
A2 counts the number of total rows of data in sheet1. =COUNT(Sheet1!E:E)
Rows 3 and 4 show the positions of each field within the record.
A6 starts a list from 1 to number of records. =SEQUENCE(MAX(OFFSET(Sheet1!E2,0,0,B1))) This uses the dynamic array functionality to spill into multiple cells.
The formula in B6 spills into multiple cells as well.
=XLOOKUP($A6#&B$3,OFFSET(Sheet1!$E$2,0,0,$B$1)&OFFSET(Sheet1!$F$2,0,0,$B$1),OFFSET(Sheet1!$A$2,0,B$4,$B$1),"")
I used OFFSET in the formulas so they can update if additional data is entered.
Finally, copy the formula in B6 to the other columns.

Excel - to format the data in a more readable way

Is it possible to get the above table in a format such as the table below, in a much easier manner without having to do a brute force approach of creating 9 columns for the LTV band and assigning it a PD value in the table?
Excel... Insert Pivot table
Select range and fill in as layed out in image below.
you can hide grand totals if you want by right clicking on the pivot table and selecting Pivot table options then the totals & filters
There are many other features as well but this gives you the general idea.
As to missing LTV values, you just need blank rows for each value so the chart pivots on all the data.
OK, Here's an idea
You can do what you want using a complicated index formula that checks the Year and the Month and other number but it's quite complicated, so.
Use a formula to create an ID column to the left of your data and you can use a fairly simple vlookup to extract the data.
The ID will be the YEAR + MONTH + B + I.TV number. On my sheet the formula is.
=C2&D2&"B"&E2
Next create your new table by listing the Years and Months and entering in the headings B1 to B9. Then put your vlookup in the first cell under B1.
=iferror(vlookup($A12&$B12&C$11,$B$2:$F$9,5,false),"")
It's not too complicated, $A12&$B12&C$11 builds the ID we want to search for using the Year, Month and Heading B1 cells. Pay attention to the way the cell references are locked as that allows you to autofill across and down while still referencing the headings etc. $B$2:$F$9 is the range you want to use for the vlookup and 5 is the column with the data you want to return.
Have a look at my example below.

Need light formula to get some counts in large data sheet

I have an employee data base that contains names and 8 movement types (Ex. Recruitment, Resignation....etc). Also I have starting head counts.
What I need to do is calculating movement counts and head counts based on the month for 12 months. Currently i am using SUMIF formula to calculate all these and the thing is excel will be very slow with all formulas. Appreciate if anyone can help me on this. See the image below for sample of the formula and I need to insert this formula in more than 600 lines.
A pivot table would be a good way to go, but by the look of your criteria you'll need to create 'helper columns' to ensure your data is ready for aggregation in a Pivot table.
For instance in your master data tab, add a new column called 'MatchesCriteria' or words to that effect, and build a formula in that column that checks for all of the criteria that you want to have the report based on, and returns a 1 or a 0, e.g.
=IF( (IF(C2="Recruitment",1,0)+IF(D2="Secondment In",1,0)) > 0 , 1 , 0)
Then run a pivot table including the 'Plant' column in your Rows, the month column in your columns and the 'MatchesCriteria' in your data values, and switch the calculation type to 'SUM' rather than 'COUNT'.
This will do the trick and will refresh in a flash compared to evaluating all of those countif statements.

Automatically sum the value in columns in excel with filtering on

I have a worksheet with 50 rows & 10 column. One of the column has an amount. I need to display this at the bottom.
I can do this by =SUM(Range) function.
However when the filter is applied and say only 5 colums are dispalyed, I need to now show the total for just these 5 columns. The filtering can be on one column or on a combination of 3-4 columns. If its possible using worksheet functions Great, else even a VBA solution would also do.
Use the SubTotal function. This can optionally ignore hiddden cells. Refer Excel help for details

Resources