Look up a date value from each cell in a column and return a year date dependent upon where date falls between two dates - excel-formula

I'm wanting to add formula to locate the Policy Year in each cell in column B (starting in B2) which is determined from interrogating the date shown in the corresponding cell in Column A and then checking whether it sits in a range (inception date and expiry date) D2:E5 The Policy Year sits in C2:C5 I've shown the values I'd expect the formula in the cells in column B to draw from Column C.
COLUMN A COLUMN B EXPECTED VALUE COLUMN C COLUMN D COLUMN E
2 April 2017 2016 2016 5 December 2016 4 December 2017
5 June 2017 2016 2017 5 December 2017 4 December 2018
6 December 2017 2017 2018 5 December 2018 4 December 2019
4 January 2018 2017 2019 5 December 2019 4 December 2020
6 August 2018 2017
4 December 2018 2017
29 December 2018 2018
6 March 2020 2019

Related

Excel function to dynamically SUM UP data based on matching rows and columns

I have a table with metrics shown as rows and month shown as columns.
Example is below:
Quarter
2022-01-01
2022-01-01
2022-01-01
2022-04-01
2022-04-01
2022-04-01
2022-07-01
2022-07-01
2022-07-01
2022-10-01
2022-10-01
2022-10-01
Month
2022-01-01
2022-02-01
2022-03-01
2022-04-01
2022-05-01
2022-06-01
2022-07-01
2022-08-01
2022-09-01
2022-10-01
2022-11-01
2022-12-01
Metrics
Jan 2022
Feb 2022
Mar 2022
Apr 2022
May 2022
Jun 2022
Jul 2022
Aug 2022
Sep 2022
Oct 2022
Nov 2022
Dec 2022
Revenue
1000
1000
1000
500
500
500
100
100
100
0
0
0
Cost
10
10
10
10
10
10
20
20
20
0
5
10
I want to have a dynamic summary table of quarterly data. I can use sumifs and look up the quarter month using this function:
SUMIFS([Value row range],[Quarter range],[Quarter wanted])
However, i still have to manually select the correct value row range to sum. Is it possible to select the entire table and then match the correct row based on matching labels (metric in this case)?
Insert Report Month
Dec-22
Last 3 quarter report
Metrics
Q2 2022
Q3 2022
Q4 2022
Revenue
1500
300
0
Cost
30
60
15
I'm aware of the index & match function, but it only looks for the first match and does not sum up all months in the same quarter.
Thanks for helping!
Excel 365 for MAC should have the BYCOL function,
Given:
Your data table is a Table named Metrics
Report_Month is a Named Range containing a "real date" in the month of the final month of the desired quarter.
The following formula will return your output and will adjust as you add columns to the data table.
A11: =Metrics[[#All],[Metrics]]
B11: =LET(x,EDATE(Report_Month,SEQUENCE(,3,-6,3)),TEXT(MONTH(x)/3,"\Q0 ") & YEAR(x))
B12: =BYCOL(XLOOKUP(TEXT(DATE(YEAR(Report_Month),MONTH(Report_Month)-9+SEQUENCE(3,,1,1)+SEQUENCE(,3,0,3),1),"mmm-yy"),Metrics[#Headers],INDEX(Metrics,XMATCH(A12,Metrics[Metrics]),0)),LAMBDA(arr,SUM(arr)))
Select B12 and fill down as far as needed.
Notes
DATE(YEAR(Report_Month),MONTH(Report_Month)-9+SEQUENCE(3,,1,1)+SEQUENCE(,3,0,3),1)
creates a matrix of the previous nine month starting dates with each column consisting of a given quarter:
So for 12/1/2022 =>
The TEXT function then formats the same as the column headers in the Metrics table.
XLOOKUP will then return the appropriate columns from the table into that matrix, and using the BYCOL allows us to SUM by column which is the relevant quarter.

Excel: Dynamic Range Date used in other fields: Sumproduct

I am using sumproduct formula to get the first four month, then the second four month, third four month of net sales until one month before today. This is my formula that I used:
=IFERROR(SUMPRODUCT($B3:$Y3*(COLUMN($B3:$Y3)>=AGGREGATE(15,6,COLUMN($B3:$Y3)/($B3:$Y3<>0),1)+4*(COLUMNS(B3)-1))*(COLUMN($B3:$Y3)<AGGREGATE(15,6,COLUMN($B3:$Y3)/($B3:$Y3<>0),1)+4*(COLUMNS(B3)))*($B$1:$Y$1<EOMONTH(TODAY(),-1)+1)),0)
However, I need to capture the same range as I have it for the net sales as for other measures like COGS in my example. I cannot use the formula above for the other measures like COGS as sometimes they are zero in the same range as in the Net Sales.But I need to capture the zeros here as well.
Example 1
Example 2
Net Sales
Jan
Feb
Mar
Apr
May
June
July
Aug
Sept
Oct
Nov
Dec
0
0
2
3
4
5
2
3
2
3
2
4
---> 1st period= 14 2nd period= 10
COGS (follows the same date range as Net Sales)
Jan
Feb
Mar
Apr
May
June
July
Aug
Sept
Oct
Nov
Dec
0
0
0
0
0
2
1
4
2
3
2
4
---> 1st period= 2 2nd Period= 11
You can leave the entire range check logic from the first formula and change just the value range, i.e first formula in my sample:
=IFERROR(SUMPRODUCT($A3:$L3*(COLUMN($A3:$L3)>=AGGREGATE(15,6,COLUMN($A3:$L3)/($A3:$L3<>0),1)+4*(COLUMN(A3)-1))*(COLUMN($A3:$L3)<AGGREGATE(15,6,COLUMN($A3:$L3)/($A3:$L3<>0),1)+4*(COLUMN(A3)))*($A$2:$L$2<EOMONTH(TODAY(),-1)+1)),0)
second formula for COGS:
=IFERROR(SUMPRODUCT($O3:$Z3*(COLUMN($A3:$L3)>=AGGREGATE(15,6,COLUMN($A3:$L3)/($A3:$L3<>0),1)+4*(COLUMN(A3)-1))*(COLUMN($A3:$L3)<AGGREGATE(15,6,COLUMN($A3:$L3)/($A3:$L3<>0),1)+4*(COLUMN(A3)))*($A$2:$L$2<EOMONTH(TODAY(),-1)+1)),0)

Dynamically Lookup Value with Between - Excel

I have a chronological list of Product, Year, Month, Profit (like below).
Summary Table
Product Year Month Profit
TV 2018 1 10
TV 2018 2 20
TV 2018 3 30
TV 2018 4 50
TV 2018 5 35
TV 2018 6 60
TV 2018 7 90
Heater 2018 1 20
Heater 2018 2 3
Heater 2018 3 8
Heater 2018 4 4
Heater 2018 5 6
Heater 2018 6 11
Heater 2018 7 1
What I wanted to do is lookup another sheet that has all of the price changes within by month and year as well as the table below shows.
Sale Price
Product Year Month Price
TV 2018 1 $1,000.00
TV 2018 4 $800.00
TV 2018 7 $950.00
Heater 2018 1 $20.00
Heater 2018 2 $60.00
Heater 2018 5 $45.00
So the end result for example, TV Month = 2 and Year = 2018, I want it to pull in $1,000 to be part of my profit calculation.
to get the correct Price, use:
=INDEX(J:J,AGGREGATE(14,6,ROW($I$2:$I$7)/(($G$2:$G$7=A2)*($H$2:$H$7=B2)*($I$2:$I$7<=C2)),1))

Expanding specific sections of a pivot table in Excel via VBA and/or jumping to original spot

I have a pivot table segmented by years, quarters and months. If I try
to expand a quarter for 2015, however, the corresponding quarter in
all other years are shown as well. How can I expand only one quarter
for one year?
- https://superuser.com/questions/1049881/expanding-specific-sections-of-a-pivot-table-in-excel
This question got no answer there, but that wasn't a programming forum. I have a similar question. Is there a VBA solution?
Alternatively, is there a VBA code to "catch" expansion clicks and then jump into the original cell on which plus was clicked?
Sample code (I want this true just for 2016):
ActiveSheet.PivotTables(1).PivotFields("Month").PivotItems("3").ShowDetail = True
Year
Month
Text
2015
1
Dummy1
2015
2
Dummy1
2015
3
Dummy1
2015
4
Dummy1
2015
5
Dummy1
2016
1
Dummy1
2016
2
Dummy1
2016
3
Dummy1
2016
4
Dummy1
2016
5
Dummy1
2017
1
Dummy1
2017
2
Dummy1
2017
3
Dummy1
2017
4
Dummy1
2017
5
Dummy1
2015
1
Dummy2
2015
2
Dummy2
2015
3
Dummy2
2015
4
Dummy2
2015
5
Dummy2
2016
1
Dummy2
2016
2
Dummy2
2016
3
Dummy2
2016
4
Dummy2
2016
5
Dummy2
2017
1
Dummy2
2017
2
Dummy2
2017
3
Dummy2
2017
4
Dummy2
2017
5
Dummy2
You can use something like this? This will be a good starting point for you, you'll have to create an IF THEN for each month
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
If (ActiveSheet.PivotTables(1).PivotFields("Month").PivotItems("3").ShowDetail) Then
ActiveSheet.PivotTables(1).PivotFields("Month").PivotItems("3").ShowDetail = False
Sheets(2).Activate
'''' Change filter options here? or have a cell selected?
End If
End Sub

Excel formula to increase month by one and week in month by one

I need a formula to increase the week in month by one as well as increase the month by one.
Basically I need an ongoing list of Mondays that would follow this pattern:
Month 1 2016, Week 1 2016, Monday = 4th Jan 2016
Month 2 2016, Week 2 2016, Monday = 8th Feb 2016
Month 3 2016, Week 3 2016, Monday = 21st Mar 2016
Month 4 2016, Week 4 2016, Monday = 25th Apr 2016
Month 5 2016, Week 1 2016, Monday = 2nd May 2016
Month 6 2016, Week 2 2016, Monday = 13th Jun 2016
as below
month date_of_first_Monday how_many_Mondays Ith_Monday_request the_date_request
1/1 =Choose(Weekday(A2,2),0,6,5,4,3,2,1)+A2 =roundup((day(eomonth(a2,0))-weekday(eomonth(a2,0),3))/7,0) =if(month(a2)=1,1,if(d1+1>c2,1,d1+1)) =b2+7*(d2-1)
2/1
3/1

Resources