Sum dynamic range in pivot table but certain row(s) - excel

I'm not quite at the level of using VBA or an issue like this, though I'm open to trying, but I am looking for a formula (or other method) that will allow me to sum the values in a dynamic range while excluding certain rows.
I have many pivot tables set up in the following fashion:
2013
Oct 10
Nov 20
Dec 10
2014 40
Jan 20
Feb 30
Mar 20
Grand Total 110
I have been trying to create a formula that sums the last 6 months, but excludes the subtotal (as seen next to 2014), so I only sum Mar-2014, Feb-2014, Jan-2014, Dec-2013, Nov-2013, Oct-2013. When we add to the source data, we will see Apr-2014, May-2014, etc, so I am trying to create a dynamic range that only counts the last six months. So far, I have used:
=OFFSET($Grand Total$110, -7, 0, 6, 0)
to try to capture the six rows leading up to the grand total row. I have tried to create an if function that says:
"if(OFFSET($Grand Total$110, -7, 0, 6, 0)=[cell with subtotal for 2014],sum(OFFSET($Grand Total$110, -7, 0, 6, 0))-[cell with subtotal for 2014],sum(OFFSET($Grand Total$110, -7, 0, 6, 0))"
but the offset function doesn't appear to act as a "range."
Is there a way to sum an offset function but exclude the subtotal row from the calculation? The problem with doing:
sum(OFFSET($Grand Total$110, -7, 0, 6, 0))-[row with subtotals]
is that once you get to Jun-2014, you will be subtracting the subtotal even though it isn't in the last 6-month range, e.g.,
2014 [Subtotal]
Jan (6 months ago)
Feb (5 months ago)
Mar (4 months ago)
Apr (3 months ago)
May (2 months ago)
June (last month)
I hope my issue makes sense and that someone might have a useful, formula-driven solution for this.

Related

Identify Gap Years Between Multiple Dates in Excel

For example, I have these list of dates (These are of type 'date')
Sept 1, 2010
July 1, 2016
July 1, 2022
The gap years between these dates are 6 years. Another Example:
Sept 1, 2010
July 1, 2012
Sept 1, 2014
July 1, 2016
The gap years between these dates is 2. How will I make a formula to identify the gap years?
You should check out DATEDIF function:
https://support.microsoft.com/en-us/office/datedif-function-25dba1a4-2812-480b-84dd-8b32a451b35c
You can create a new column:
Gap_row = Previous Row - Current Row
D2 = IFERROR(IF(D1<0;0;C2-C1);0)
Then create a pivot table for year and show Max(Gap_Row).
The Grand total for Max of Year Gap is the Year Gap for those rows:
Starting at your second date, just do =YEAR(A2)-YEAR(A1)

How to sum last 3 months by looping through a list in excel?

I have a list of values for each month 1 to 12 in excel. When the quarter ends in December then it should sum the values for the quarter Oct, Nov, and Dec i.e. Month 10, 11, and 12. The current function used is an offset function
=SUM(OFFSET(INDEX($F$999:$F$1008,MATCH(MONTH($B1013),$E$999:$E$1008)),0,0,-3,1)).The formula works well when the starting position is Mar, Jun, Sep, and December. However, assume the quarter ending month is Jan. Then using the above function will only sum values for Jan because above that there are no values 2 months prior.
Desired outcome: If the quarter ends in Jan then it should loop through the list and sum Nov, Dec, and Jan. The goal is to perform a sensitivity analysis because the quarter ending month can be any month, and based on the quarter ending month it will sum up all the values for the quarter.
The list is given below, so if the quarter ends in Feb it should sum (Dec) 10% + (Jan) 3% + (Feb) 6% = 19%
Jan 1 3%
Feb 2 6%
Mar 3 2%
Apr 4 9%
May 5 5%
Jun 6 8%
Jul 7 3.2%
Aug 8 12%
Sep 9 6.5%
Oct 10 5.6%
Nov 11 8%
Dec 12 10%
The trick is to generate a numeric sequence that will match the required months.
Note that, in your table, the month number = the index into the table.
A formula that will generate the required sequence, such that if you the quarter ending month is January (eg month number 1) => {11,12,1} is
Office 365: =SUM(INDEX(monthly,MOD(SEQUENCE(3, ,F2+12-2)-1,12)+1,3))
older versions: =MOD(ROW(INDEX($A:$A,1):INDEX($A:$A,3))+F2+12-4,12)+1
where F2 contains the month number of the ending quarter.
So for O365:
=SUM(INDEX(monthly,MOD(SEQUENCE(3, ,F2+12-2)-1,12)+1,3))
or : =SUM(XLOOKUP(MOD(SEQUENCE(3, ,F2+12-2)-1,12)+1,monthly[monthNum],monthly[perCent]))
where monthly is the name of your table
For earlier versions, try:
=SUM(INDEX(monthly,MOD(ROW(INDEX($A:$A,1):INDEX($A:$A,3))+F2+12-4,12)+1,3))
or even:
=SUM(INDEX(monthly,N(IF(1,MOD(ROW(INDEX($A:$A,1):INDEX($A:$A,3))+F2+12-4,12)))+1,3))
In some earlier versions of Excel, you may need to "confirm" this array-formula by holding down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula as observed in the formula bar

Excel formula to fetch dates as a flag (1,0) for months from now into past 1 yr.As in Past 3month,Past 6 months and Year to date

I have dates column in spreadsheet.I need help with Excel formula to fetch dates as a flag (1,0) for months from now into past 1 yr. As in Past 3 month,Past 6 months and Year to date.
the latest date in the data set is 2/1/2019.This is what I used for fetching for YTD but it fetches only the 12th month from max date in the column as opposed to all the 12 months.
=IF(B3=(DATE(YEAR(MAX($B:$B)),MONTH(MAX($B:$B))-12,1)),1,0)
I used below formula for R3M 3months,but this would make the YTD formula to long and will take long time to run.
=IF(B3=(DATE(YEAR(MAX($B:$B)),MONTH(MAX($B:$B)),1)),1,IF(B3=(DATE(YEAR(MAX($B:$B)),MONTH(MAX($B:$B))-1,1)),1,IF(B3=(DATE(YEAR(MAX($B:$B)),MONTH(MAX($B:$B))-2,1)),1,0)))
Is there any way the formula can be shortened.
Month, CMDATE_FLAG, R3MDATE_FLAG, YTDMDATE_FLAG,
2/1/2018, 0, 0, 1,
2/1/2018, 0, 0, 1,
3/1/2018, 0, 0, 0,
3/1/2018, 0, 0, 0,
This is what I get for YTD.I expect '1' under YTD flag from Feb 2018- Feb2019(12 months).
Thanks for your help.
Perhaps something like:
=IF(B2>=EDATE(MAX(B:B),-12),1,0)
This formula will include 13 months. You'll have to modify it a bit depending on whether you want to exclude 2018 Feb or 2019 Feb from being marked.
To exclude only 2019 Feb, then try:
=IF(AND($B2<> MAX($B:$B),$B2>=EDATE(MAX($B:$B),-12)),1,0)
To exclude only 2018 Feb, try:
=IF(B3>EDATE(MAX(B:B),-12),1,0)
You can use a similar principal for the other month flags.
The formulas assume the dates in column B are all on the first of the month, as you show in your data example. If that is not the case, the formula may need to be modified.

Numerical month to character month in excel

Is there a pre-installed function that directly converts 08 to Aug, 10 to Oct?
Currently I use text(date(0,have,1),"mmm").
You could simplify like this: =TEXT("8/0","mmm").
Update
I've come up with a new technique: =TEXT(number * 30,"mmm"):
How it works
Dates are stored as numbers in Excel. The number 1 is the date Jan 1, 1900; 2 is Jan 2, 1900; etc.
The 30th day in 1900 is in January; the 60th day is in February; the 90th day is in March.
Every multiple of 30 between 30 and 360 is in a different month. So we can simply multiply 30 by a number between 1 and 12, and the TEXT function will give us the month.
You can use
MonthName(yourmonthNumber)
or
MonthName(yourmonthNumber, True) 'to abbreviate the name
Or did you mean a worksheet function?

Two conditions have to be true then be counted

I'm working on a spreadsheet that two conditions have to true in order to be counted. If the month is January, and the number next to it is less than or equal to 30, then it's counted. Same rule applies for all the other months.
Thus far, I have:
=COUNTIFS(Sheet1!D2:D7,(SUMPRODUCT(--(MONTH(D2:D7)=1))),Sheet1!E2:E7,(COUNTIFS(E2:E7,"<=30")))
For example:
Column D
Jan 1, 2014
Feb 3, 2014
Feb 16, 2014
Mar 5, 2014
Mar 13, 2014
Mar 29, 2014
Column E
37
25
30
31
1
16
Outcome
Jan 0
Feb 2
Mar 2
It's fairly easy. Try this:
{=SUM(IF(MONTH($D$2:$D$7)=1,1,0)*IF($E$2:$E$7<=30,1,0))}
Of course you can replace the =1 part with a reference to a cell with the month number or even =MONTH(H2), for example, given a cell with a date in it so you can build your formula as a table.
Note: the only trick to this is that the formula must be entered as an array formula. So do CNTL+SHIFT+ENTER when entering in the formula.

Resources