Nested If And Formula in Excel - excel

I have an excel document with various dates in Column A ranging from April, 2014 through April 2017.
I need to assign a number based on the month and year - April 2014 is 23 and it drops by 1 every month going forward. So May 2014 is 22, June 2014 is 21 and so forth. Once I get to March 2016, or 0, all dates greater than that are also 0. My issue is that excel is treating April 2014 and April 2015 the same - they are both returning a value of 23.
Here is my code:
=IF(AND(MONTH(A2)=4,YEAR(A2=2014)),"23",IF(AND(MONTH(A2)=5,YEAR(A2=2014)),"22",IF(AND(MONTH(A2)=6,YEAR(A2=2014)),"21",IF(AND(MONTH(A2)=7,YEAR(A2=2014)),"20",IF(AND(MONTH(A2)=8,YEAR(A2=2014)),"19",IF(AND(MONTH(A2)=9,YEAR(A2=2014)),"18",IF(AND(MONTH(A2)=10,YEAR(A2=2014)),"17",IF(AND(MONTH(A2)=11,YEAR(A2=2014)),"16",IF(AND(MONTH(A2)=12,YEAR(A2=2014)),"15",IF(AND(MONTH(A2)=1,YEAR(A2=2015)),"14",IF(AND(MONTH(A2)=2,YEAR(A2=2015)),"13",IF(AND(MONTH(A2)=3,YEAR(A2=2015)),"12",IF(AND(MONTH(A2)=4,YEAR(A2=2015)),"11",IF(AND(MONTH(A2)=5,YEAR(A2=2015)),"10",IF(AND(MONTH(A2)=6,YEAR(A2=2015)),"9",IF(AND(MONTH(A2)=7,YEAR(A2=2015)),"8",IF(AND(MONTH(A2)=8,YEAR(A2=2015)),"7",IF(AND(MONTH(A2)=9,YEAR(A2=2015)),"6",IF(AND(MONTH(A2)=10,YEAR(A2=2015)),"5",IF(AND(MONTH(A2)=11,YEAR(A2=2015)),"4",IF(AND(MONTH(A2)=12,YEAR(A2=2015)),"3",IF(AND(MONTH(A2)=1,YEAR(A2=2016)),"2",IF(AND(MONTH(A2)=2,YEAR(A2=2016)),"1",IF(AND(MONTH(A2)=3,YEAR(A2=2016)),"0",IF(AND(MONTH(A2)>3,YEAR(A2=2016)),"0","0")))))))))))))))))))))))))
Any help is greatly appreciated!

I would use yearfrac instead.
=IF(A2>DATE(2016,3,1),0,ROUND(YEARFRAC(DATE(YEAR(A2),MONTH(A2),1),DATE(2016,3,1))*12,0))
Yearfrac between your date (A2) and date(2016,3,1) will give you the portion of a year between the two which you can multiply by 12 and round to get the month number. The if statement takes care of months after March.

Try this:
=IF(A2<Date(2016,3,1),DATEDIF(A2,DATE(2016,3,1),"m"),0)

Related

WEEKNUM across multiple years

I am doing a cohort analysis for a subscription service from September 2021 - January 2023 and using the WEEKNUM formula, but of course each year starts on a different day and I am struggling to figure out how to mitigate this for all dates on the worksheet. Additionally, I just want there to be 52 weeks each year (not 53, week 52/1 can overlap years).
Presumably it will need to be some sort of IF statement but I just can't seem to visualise it!
I have tried =WEEKNUM(D2,15), which is fine for days in 2021 as it starting on a Friday, but not for days in 2022 and 2023 when I drag the formula down all of the dates
I think I've figured out the answer!
=IFS(D2<>"2023",(WEEKNUM(D2,1)),D2<>"2022",WEEKNUM(D2,16),D2<>"2021",WEEKNUM(D2,15))
I have tested it against some of the dates manually and it seems to hold true

Excel - count a specific value based on a part of another cell

I thought this would be a no brainer. But I really need help to solve it.
I have a row of dates: 10 july 2020, 11 july 2020 and so on (Swedish excel).
Below each date are strings for example "FP". I wish to achieve a counter for each "FP" that is below a specific month of a year, such as july 2020.
The way I approached this was with
=COUNTIFS(G1:UG1;"*july 2020";G2:UG2;"FP")
However the * doesn't do what I want it to. Is there another way to do this?
Please help! :)
The dates are true dates and as such the july 2020 is just a format of a number and not actually there.
Instead BookEnd the date:
=COUNTIFS(G1:UG1;">="&DATE(2020;7;1);G1:UG1;"<"&DATE(2020;8;1);G2:UG2;"FP")

Excel formula based on previous month

I inherited a worksheet that has a number of formulas (see below). The formula is trying to pull the rate from the previous month but once the month changes the amount is 0, so the current month = 0. Surely there must be a better way to write this formula but I'm stuck. Any suggestions would be greatly appreciated. Thanks for your help.
Jan 500
Feb =IF(MONTH(TODAY())=2,x7,"0")
Mar =IF(MONTH(TODAY())=3,Y7,"0")
Apr =IF(MONTH(TODAY())=4,Z7,"0")
May =IF(MONTH(TODAY())=5,AA7,"0")
Jun =IF(MONTH(TODAY())=6,AB7,"0")
I think what you need is to just check to see if today's date is less than the month you are evaluating for.
This may be what you are looking for:
Feb =IF(MONTH(TODAY()) < 2,0,x7)
March =IF(MONTH(TODAY()) < 3,0,y7)

Filter dates by month in pivot table that doesn't start with the 1st of every month

Does anyone know how to filter dates by specific dates by month such as Jan 15 to February 15, Feb 15-March 15....etc on pivot table in excel?
My data is January 15 2017 to January 15 2018, so I like to filter it by specific dates but so far it's only letting me do the number of days which is not accurate since feb has only 28 days. thank you!

How to count running months of a specific year?

I'm currently struggling with calculating the running months depending on the year. I have the following table:
Received Month Received Year
Feb 2018
Feb 2018
Mar 2018
... ...
Nov 2018
Nov 2018
Dec 2018
Dec 2018
Jan 2019
Jan 2019
Feb 2019
I was using this formula to count the # of unique months (running months in 1 single cell [C1]);
=SUMPRODUCT(1/(COUNTIF(KAIZEN_Table[Received Month],KAIZEN_Table[Received Month])))
This was working great in 2018, it gave me 11 (Feb - Dec).
I have to add a filter that also checks if the year is 2019. I can't remove 2018 in the table because the operators are still using the 2018 lines. The filter is just here to set a KPI for 2019.
For some reason I can't figure out how to add the year. I tried;
=SUMPRODUCT(1/(COUNTIFS(KAIZEN_Table[Received Month],KAIZEN_Table[Received Month],KAIZEN_Table[Received Year], "2019")))
This is just giving me a 0.
Any suggestions on this? VBA code is also fine.
Edit: After extensive googling I found a working formula, for whoever might be interested in this.
=SUM(IF(FREQUENCY(IF(tbl[Year]=2019,MATCH(tbl[Month],tbl[Month],0)),ROW(tbl[Month])-ROW($L$5)+1),1))
L5 = First row of tbl[Month]
I have my data in A1:B14, the formula I've used is an array one
=SUM(1/(COUNTIFS($A$1:$A$14,$A$1:$A$14,$B$1:$B$14,$B$1:$B$14)))
however,
=SUMPRODUCT(1/(COUNTIFS($A$1:$A$14,$A$1:$A$14,$B$1:$B$14,$B$1:$B$14)))
would suffice
To do a particular year, you could do something like this
=SUM(($B$1:$B$14=2019)*(1/COUNTIFS($A$1:$A$14,$A$1:$A$14,$B$1:$B$14,B1:B14)))
Another approach is to use a Pivot Table.
On the Create Pivot Table dialog, select to Add this data to the Data Model
If you do this, you will note that one of the options in the Value Field Settings will be Distinct Count
Drag Received Year to the Rows Column; Received Month to the Values column, and select Distinct Count for the Value Field Setting

Resources