Trying to calculate between 2 Table Queries based on date range - excel-formula

So I have an issue where I am trying to apply a calculation to data in each column of Table 1 in my "LP_Input" query incorporating the figure on Table 2 in my "MA_Input" query. The main issue is that the figures on Table 2 are based on date ranges identified in 2 columns "Start Date" "End Date" and the figure used changes over time so Client 1 may have 2 date ranges which use a different figure.
In excel the formula would look like this: =((1+C16)/((1+C173)^(1/12)))-1
Where C16 is the corresponding value in Table 1; matching date and client name with C173 from the Table 2.
Table 1
Table 2
One of the options I played with was converting Table 2 to mimic the layout of Table 1 effectively generating the MA value against each month end date between the date range as an individual Cell. Then I could at least work some sort of custom column to calculate per client or perhaps use Powerpivot to do the calculations.
EDIT: See Below relation - That block of figures are related to that range of dates and as such need to utilise the yellow boxed figure in the calculation.
The formula example was taken from the old method so my apologies the Cell Ref is a bit useless but as a translation to make more sense:
C16 = any of the figures in the block of data
C173 = this would be the yellow boxed figure
Therefore for every instance of C16 the calculation would need to be applied using the figure C173 as those C16 figure fall within the highlighted date range. Hopefully that's more useful.
Example Data Relationship

Related

Excel - Get unique count based on multiple columns (including date)

I'm trying to get a unique count of data in Column B that fall into the month of June (Column A date field)
Screenshot of Spreadsheet
I highlighted the rows that fall within June in Orange and the duplicate data in red to make it easier to view.
Count Total formula is a simple:
=COUNTA(A:A)-1
Unique Data formula is:
=SUMPRODUCT(1/COUNTIF(B2:B21,B2:B21))
Count June formula is:
=COUNTIFS(A:A,">=01/06/2020",A:A,"<30/6/2020")
But I can't figure out how get a count of unique data that falls within June (expected result is 13)
I've tried filter/unique formulas based on
Excel - Count unique values that meets multiple criteria
But I just can't get it to work. I know I could do it with VBA but this is part of a larger spreadsheet and every other part of the spreadsheet I've been able to do with Formulas, so would like to be able to do this last part with formulas too.
Anyone can help will be a life saver, it's been driving me nuts for the last couple hours.
In Excel 2016, which does not have the UNIQUE or FILTER functions, you can use this somewhat convoluted formula for a Unique count of June entries:
=SUM(IF(FREQUENCY(IF(LEN(IF(MONTH(Table1[Date])=6,Table1[Data],""))>0,MATCH(IF(MONTH(Table1[Date])=6,Table1[Data],""),IF(MONTH(Table1[Date])=6,Table1[Data],""),0),""),IF(LEN(IF(MONTH(Table1[Date])=6,Table1[Data],""))>0,MATCH(IF(MONTH(Table1[Date])=6,Table1[Data],""),IF(MONTH(Table1[Date])=6,Table1[Data],""),0),""))>0,1))
This part of the formula: IF(MONTH(Table1[Date])=6,Table1[Data],"") returns an array consisting of all of the June Data entries.
The LEN(... eliminates the resultant blanks
The Frequency function will then have us wind up with a count of 1 for each entry.
Then we just add it up.
Note that I used a Table and structured references, but you can convert it to regular addressing if you need to.
Of course, if you had Excel O365, you could use the simpler:
=COUNTA(UNIQUE(FILTER(Table1[Data],MONTH(Table1[Date])=6)))

Excel Generating a table based on positions in another table

I have a forecast for a number of countries, and I want to simulate how different launch years for these countries will impact the total sales for each year.
Say I have these forecasts for each market (Denmark, Norway and Finland):
What I would like to achieve, is to be set the launch year in a setup table like this:
And then finally end with a table, where each country's forecast is repositioned according to the launch year I define in the previous setting. This would ultimately look like this, based on my example:
I.e. the first year of Denmark's forecast is shown in year one (based on the input from cell H2), the first year of Norway's forecast is shown in year 3 (based on the input from cell H3) and vice versa for Finland.
So with this in hand, the last table (in A8:E11) will update when I change the inputs for launch year in each country.
Do you know of a good way to do this in Excel?
As #JosephMason said. INDEX/MATCH will return your figures.
Simple version:
In cell B9 in your example:
=IF(B$8-$H2+1<=0,0,INDEX($B$2:$E$4,1,B$8-$H2+1))
Cell B10:
=IF(B$8-$H3+1<=0,0,INDEX($B$2:$E$4,2,B$8-$H3+1))
Cell B11:
=IF(B$8-$H4+1<=0,0,INDEX($B$2:$E$4,3,B$8-$H4+1))
Slightly more complex version:
So you don't need to change the row number in the INDEX function (entered in B9 and dragged across/down):
=IF(B$8-$H2+1<=0,0,INDEX($B$2:$E$4,MATCH($A9,$A$2:$A$4,0),B$8-$H2+1))
Looks it all up version:
So the order of countries in G2:G4 doesn't matter:
=IF(B$8-INDEX($H$2:$H$4,MATCH($A9,$G$2:$G$4,0))+1<=0,0,INDEX($B$2:$E$4,MATCH($A9,$A$2:$A$4,0),B$8-INDEX($H$2:$H$4,MATCH($A9,$G$2:$G$4,0))+1))
I would use an INDEX function with a MATCH function for the row referencing on the country, and another MATCH function for the year column referencing off your input.
The simplest way to do this that I can think of now is via pivot.
First you will need to redimension this table
via pivot to this by sum or max + tabular format + repeat item labels + off all grand totals + rename value from sum of 1 to 1 (add a space)
Copy and paste the pivot as value into a new range and add in additional column called "new seq", use the formula below for "new seq" column which references to the launch year table next to it.
=INDEX(G$2:G$4,MATCH(A2,F$2:F$4,0))+NUMBERVALUE(B2)-1
Next, just pivot the new range to get the final result.
Just change the launch year value in launch year table and refresh pivot to see the values change.

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.

Countif with dynamic headers

Good afternoon! I'm trying to get a Countifs or Index Match statement to count the number of times a value occurs in another table. The example:
On my report sheet, Column A contains 10 different statuses, such as Green, Yellow, Red etc.; Row 1 contains six dates, such as 1/31/2015, 2/28/2015, etc. These dates are calculations. The last date references my date worksheet and the five other use EOMONTH to get the month end for the five prior months.
On my data table, I have 7 descriptive columns (such as Type, Make, Model, etc) and then we begin date columns: 1/31/2010 all the way to 7/31/2015. I add a new column each month (I know, I don't like it either, but unfortunately we don't have a time series database).
What I need to do is have a Countifs or Index Match that pulls the date from my report tab, goes and finds it in the header row of my tblTrends, and then counts all those statuses that are Green, and if it's a SUV (for example).
Thoughts?
Thx!!
G
At it's most basic, you'd want something akin to:
=COUNTIFS(TypeRange,"SUV",FirstMonth,Status)
So let's say your data table starts in column L, and the first date column is O:
=COUNTIFS($L$1:$L$100,"SUV",O$1:O$100,A$2)
As you drag this formula across the different dates, it will move the date reference over one to the next month.
If you need it to dynamically determine the date column, I'd recommend OFFSET, which dynamically select a range. However, note that OFFSET is a "volatile" formula, which means it re-calculates anytime a change is made anywhere in the file, which can lead to pretty slow load times if not used sparingly.
=COUNTIFS($L$2:$L$100,"SUV",OFFSET($N$2:$N$100,,MATCH(B$1,$O$1:$Z$1,0)),$A2)
The OFFSET starts on column N, because that's the first column before the columns we want (the date columns). The MATCH tells it how many columns to OFFSET from here.
If you're going to use this over a large amount of data, then you could avoid using the OFFSET formula by creating a dynamic table. This table would only contain data for the six months you're interested in, by utilizing INDEX/MATCH, and you could run your COUNTIFS off this table, instead, using the original, basic method I first described. I can go into detail if you're unsure what I mean.

Resources