Count entries for current month - excel

So I want to count how many entries have been filed in the month of July. Could someone help me how to do that so every month when the new data is added it automatically updates and gives new data for each month. I know I need to use combination of =CountIfs, =today, Month, =Year but not sure how exactly to formulate that.

Use SUMPRODUCT()
=SUMPRODUCT((YEAR($A$1:$A$100)=YEAR(TODAY()))*(MONTH($A$1:$A$100)=MONTH(TODAY())))
This will count every month that is the same as the month today.

Here is the COUNTIFS version for the original question
=COUNTIFS($A$1:$A$100,"<="&EOMONTH(TODAY(),0),$A$1:$A$100,">"&EOMONTH(TODAY(),-1))
or
=COUNTIFS($A$1:$A$100,"<"&DATE(YEAR(TODAY()),MONTH(TODAY())+1,1),$A$1:$A$100,">="&DATE(YEAR(TODAY()),MONTH(TODAY()),1))
You might be thinking of something like =countifs(month($A$1:$A$100),month(today)) but unfortunately it doesn't work - the first value in the countifs has to be a range and you can't use a function here so it has to be done with a SUMPRODUCT as in Scott Craner's answer.

Related

Excel count number of dates (in rows) which fall under a predetermined period

So i have been playing with Excel for a while, and one thing led to another, i wanted to try this: How would i calculate the instances of dates (such as below) in one sheet
And count which of those dates fall under the 30/60/90 day period (such as below) I'm looking to see if i could have a final tally up the number of instances of dates which fall below 30/60/90 days to the current date in another sheet.
Using the table example gave that i would know that 2 dates fall under the 30/60 days period, and one fell under the 90 days period
Is there a solution to my predicament?
Edit: More accurate question
Use nested IF() function.
=IF(TODAY()-B2<=30,30,IF(TODAY()-B2<=60,60,IF(TODAY()-B2<=90,90,"Other period")))
Or try IFS() if you have Excel-365.
=IFS(TODAY()-B2<=30,30,TODAY()-B2<=60,60,TODAY()-B2<=90,90)
Another option is-
=XLOOKUP(TODAY()-B2,{30,60,90},{30,60,90},"Other Period",1)
You could try:
Formula in E2:
=SUMPRODUCT(--(CEILING(D$6-B$2:B$6,30)=D2))

Easy Excel Formula

Have an excel question. I am looking to see if something states "complete" in one cell and if yes then look at a date in another cell and then count how many are within 30 day period of today's date. Below I know its wrong but might be able to get a better idea of what I am trying to do.
=sumifs(Main!B:B="Completed",Main!H:H,"<30")
You should be using COUNTIFS:
For 30 days window in the future:
=COUNTIFS(Main!B:B,"Completed",Main!I:I,">="&TODAY(),Main!I:I,"<"&TODAY()+30)
For 30 days window in the Past:
=COUNTIFS(Main!B:B,"Completed",Main!I:I,"<"&TODAY()+1,Main!I:I,">="&TODAY()-30)
=COUNTIFS(Main!B:B,"Completed",Main!H:H,"<="&TODAY(),Main!H:H,"<"&TODAY()+30)

Excel - count WORK days in each month between two dates

I'm trying to figure out the number of workdays between two dates for each month. I have found this answer already and it works just fine for the days.
I would now like to know, how many workdays there are in each month. Meaning (again based on the linked answer), I'm here:
and would like to get to this here:
There is a function called Networkdays. You can find details here and here. You will need to know which holidays you have in-between.
I usually generate a list of all dates in a calendar year (or download it) and then mark the holidays I want to exclude with an x.
You are looking for the NETWORKDAYS function.
Based on the linked result, something like the below should work (and be easy to modify based on how your sheet is set up):
=IF(
IF(C2$3>$B2, NETWORKDAYS(B$2+1, $B2), NETWORKDAYS($A2, C$2)-SUM($B3:B3))<0,0,
IF(C2$3>$B2,
NETWORKDAYS(B$2+1, $B2),
NETWORKDAYS($A2, C$2)-SUM($B3:B3)))
For example:

How to reference one value to various cells, depending on a date?

Please have a look at the picture I attached, it'll make understanding my problem easier because it's hard to describe.
In the first table, I have capacity data for a product. The capacity changes by the date indicated in the column, i.e. from July 2017 the capacity would be 56, from December 2018 78, and from October 2019 99. The reason why I don't write down the capacity for every month is that I want to save columns.
In the second table, I have every month. I want to reference the correct capacity for each month, e.g. it would be 56 for every month until December 2018.
I have been considering an =INDEX function, but it seems to complex for that. Is there a way to reference like this without using VBA? Would the VBA solution be simple? Or am I forced to write a column for every month's capacity in the first table? Thank you!
https://i.imgur.com/mRoBtTo.png
You can simply use several IF statements to compare the month in your column with the months given in your first table, and put the value of the correponding month.
Let's admit your first row is 1 and first column is A, it should give something like:
= IF(D7>=$F$2; $F$3; IF(D7 >= $E$2; $E$3; IF(D7 >= $D$2; $D$3; "")))
I dont see you columns and rows so i hope you will change them correctly on this formula:
=HLOOKUP(C111,$C$106:$P$107,2,TRUE)
C111 is the cell above your red row.
$C$106:$P$107 is the tableof capacities, i know it is bigger then the current one so you see you can add more columns.
2 is the row number from the capacity table.
true is becouse you dont want it to be the exact value it will take the previews in hte order of items
Both previous answers work perfectly, but I would go this way-
You don't actually need an if to find the previous capacity. you can simply use the approximate match (similar to the hlookup answer) in an index formula
=+INDEX($B$4:$E$5,MATCH($B$9,$B$4:$B$5,0),MATCH(C9,$B$4:$E$4,1))
The product $B$9 matches exact (0), but the date C9 is bigger than or equal (1).
$B$4:$E$5 is the source of capacity and
C9:AF9 the date timeline
Final advantage would be that you can have several products to index, not only a single one.
Could you please try the below formula and provide feedback please?
=IF(AND(D8>=D2,D8<E2),"56",IF(AND(D8>=E2,D8<F2),"78",IF(D8>=F2,"99")))

How to filter data of last record of each week

I have a big data set of daily selling value of a particular ITEM. I want to know what was the price of ITEM on the last day of each week. Typically the last working day is Friday but if you don't have data for Friday then we need to get the previous working day data (Thursday).
Monday is considered the First day of week.
My Data looks something like this:
Data is in cells A2:C13.
My expected output is shown below:
Please help with VB macro or even simple excel formula.
You may want to try using a formula using the LOOKUP function, to search the list from bottom to top.
Afterward, a combination of INDEX and MATCH may get you on the right path as well.
Edit: I realize now that I was leading you astray because I thought you were asking something else! The most straightforward way I can see is as follows:
use WEEKDAY() to pull out the weekday values (as you did), except leave the values as numbers (with 1 being Sunday and 7 being Saturday).
Check each of these days to see if it precedes (i.e. has a lesser value) than the day above it. If not, we know that the week started over, and that cell is the last day of the week. Therefore, display its value.
Of course, this assumes that there are no Saturdays in your data - otherwise, Saturday would be listed as the end of the week. If you're crafty you can fix this dilemma though!
Thanks, Tyler.
Your suggestion helped me a lot in putting efforts in the right direction.
The way I did is as follows:
First I sorted my data in decreasing order of date so that I can have all the latest data at the top.
Range("AW4:BE999999").Sort Key1:=Range("BC4:BC999999"), order1:=xlDescending, Header:=xlYes
From Date created a string of "YEAR"&"WEEKNUM". This way I was able to group all the days in a specific week. Formula Used is:
=(TEXT(BC5,"yyyy"))&(TEXT(WEEKNUM(BC5),"00"))
Then I gave a unique Number to each record. The best way I could think of is to give the row number where record belongs.
=ROW(AY5)
Now using VLOOKUP function I got all the records matching string I have created in step 2
=VLOOKUP(AZ5,AZ:BD,5,FALSE)
I applied the above formula to get all the columns that I need.
Now I removed all the duplicate rows using below formula:
Cells.RemoveDuplicates Columns:=Array(1)
Now the remaining rows are the expected rows.
There may be a better way to do this but this is my first time with excel macro and formulas, so feeling happy.
Please comment other better ways to do this. It's always good to keep on improving our work.

Resources