Count amount of entries within one year and other criteria - excel

For my Pilots logbook I am trying to be able to make a easy search where you can enter certain criteria and get the amount of landings and time in flight.
For example you could enter the departing airport and it would give you the amount of takeoffs from that airport.
So far I have been able to get the results using the COUNTIFSfunction.
Trying to add a field, where you can enter a year and it would only count the occurrences in that year is giving me a hard time!
The date is in the following format: dd.mm.yyyy. The year to search for would be entered in a cell (yyyy).
Just adding it to the COUNTIFSobviously doesn't work. I know I can get the year out of the date using the YEARfunction, yet I can't figure out a way of including this into the COUNTIF.
Any Ideas?
CODE:
=COUNTIFS(Logbook!F3:F2000,IF(ISBLANK(B30),"*",B30),Logbook!C3:C2000,IF(ISBLANK(C30),"*",C30),Logbook!K3:K2000,IF(ISBLANK(D30),"*",D30),Logbook!L3:L2000,IF(ISBLANK(E30),"*",E30),Logbook!G3:G2000,IF(ISBLANK(F30),"*",F30),Logbook!B2:B2000,B30)
Where B30 is the cell with the year, and B2:B2000 being the cells with the dates.
I also tried to compare by the text (somewhat like RIGHT(Logbook!B2:B2000,4)=B30) but it doesn't do anything but returning a #VALUE error.

Seems like a really good case for PivotTables and slicers... You could even avoid the RIGHT() formula if you format the dates; then you could use the built-in group feature of PivotTables.

Related

How to best find the minimum positive difference of a value compared to a table efficiently using one Excell cell only?

I want to avoid VBA as much as possible and try to find a solution in a single cell--if possible. I have been trying to find a way to do so, but I have no idea how to.
The logic is summarized in the image below. In words, the conditions are:
Search Name is looked for in the Name column of the right table.
Search Date has to be greater than the Date in the right table.
Search Date minus Date has to be the positive minimum value.
Return the Pay that matches the criteria--which is 500 in the example.
You could use the following array formula (i.e. you need to enter it with Ctrl+Shift+Enter, if you are successful, you will see the braces appear in the formula bar):
=INDEX(G:G,MATCH(A2,IF(F:F=B2,E:E)))
The formula will return #N/A if there are no dates earlier than the Search Date.
NOTE: The dates have to be sorted in ascending order for this to work
EDIT: A little more robust that doesn't require sorting:
=INDEX(G:G,MATCH(MAX(IF((F:F=B2)*(E:E<A2),E:E)-A2),IF((F:F=B2)*(E:E<A2),E:E)-A2,0))
Note: Since this doesn't use MATCH, you won't get #N/A in case there are no dates earlier than the Search Date and you will instead get Pay (i.e. the header). If you want to get something else, then you can wrap the whole function in an IFERROR, relying on the fact that excel returns an error if one attempts to multiply a text with a number, something like this:
=IFERROR(Formula*1, "No pay matched")
This can be done with SumProduct, which does not require Ctrl-Shift-Enter
=SUMPRODUCT($G$2:$G$9,(A2>$E$2:$E$9)*(MONTH(A2)=MONTH($E$2:$E$9)*($F$2:$F$9=B2)))
The logic commands that the Search Date is in the same month as the Date column.
If you have the new Dynamic Array functions, that are currently in preview in the Insider Fast build of Excel 365, you can use
=FILTER($G$2:$G$9,(A2>$E$2:$E$9)*(MONTH(A2)=MONTH($E$2:$E$9)*($F$2:$F$9=B2)))

Excel SumIF dates in another cell are from previous month

I have a table of mortgage loans in Excel. I want to sum the loan amounts(B:B) for loans whose lock dates(D:D) were in the previous month. I am trying to use the "SumIF" function to pull criteria from a different cell as below:
=SUMIF(range,"*"&A1&"*",sum_range)
But I want to pull a "date between previous month start and previous month end" range. I've used this for another function and it has worked.
D:D,">="&EOMONTH(TODAY(),-2)+1,D:D,"<"&EOMONTH(TODAY(),-1)+1
Now, I am trying to infuse the latter function into the first, something like this, but it is not returning anything. Any help would be much appreciated!
=SUMIF(Data!D:D,"*">="&EOMONTH(TODAY(),-2)+1,Data!D:D,"<"&EOMONTH(TODAY(),-1)+1)*",Data!B:B)
Use SUMIFS when you have multiple criteria, and from your explanation, it seems like you don't need the wildcard "*".
=SUMIFS(B:B,D:D,">="&EOMONTH(TODAY(),-2)+1,D:D,"<"&EOMONTH(TODAY(),-1)+1)

Using the 'TODAY' function

My spreadsheet is to show me how many days active a certain field has been.
For this I am trying to find a formula which will automatically take the entered date from one cell and deduct it from "todays" date.
As an example I have used =DATEVALUE("22/04/2017")-TODAY() - and although this works, i am unable to drag the formula down into other cells, to auto populate when a date has been entered/ amended. I'm having to enter the formula above every time, and if the date changes, as an example from the 22/04/2017 to the 20/04/2017, I would have to manually amend the formula too. How can I get it just pick up the date in that particular cell and deduct "today" from it?
Sorry if i'm rambling, I just don't know if I'm explaining myself properly.
Thank you
Typically, 'how many days active a certain field has been' would be a positive number (i.e. the number of days). Reverse the subtrahend and minuend to get a positive integer like this,
=today()-a3
To avoid getting 5/15/2017 or 42,870 as the result when A3 is blank, check to see if there is something in A3 before attempting subtraction.
=if(len(a3), today()-a3, text(,))

Finding less than between months/string

I'm needing to find the difference between two months in excel. One month is listed as a string, the other I'm calculating by doing
=TEXT(NOW(),"mmmmmmmmmmmm")
I've attempted to get values that I could then use to display a Yes/No based on it being less than. Here is what I've tried, they are on individual lines.
=DATEDIF(M9,G19,"YM")
=IF(M9>G19,Yes,No)
The DATEDIF, I was looking to find number of days, then wrap it in an IF and showing Yes/No depending on positive/negative numbers.
You need to compare them as dates not as strings/text.
Please can you include what the month listed as a string looks like?
If you have December as a string in cell A1 for example, you would convert to date using: =DATEVALUE(1&LEFT(A1,3))
Then get the current date with now(), without turning to text, and compare as dates.
Full thing: =IF(now()>(DATEVALUE(1&LEFT(A1,3))),"Yes","No")

Excel - Get Unique values in Column in between dates in another column

I have been trying to get this for a couple of days now. I have read several articles on similiar achievements but have been unable to get any of them to work.
Column A has a list of names that represent a person attending that work day; column I represent the date for that work day.
I need to look through a date range for one week in "I" and get the unique count of names that were present in "A".
I can get the count but I cant get th unique count using
=COUNTIFS('DIRECT TIME'!I:I,">="&B25,'DIRECT TIME'!I:I,"<="&C25)
Can someone help me figure this out. I have tried to implement functions i have found online using frequency and sumproduct/count but have been unable to get any of them to work.
Thanks,
-Joseph
Generically you can use a formula like this:
=SUM(IF(FREQUENCY(IF(Dates>=A1,IF(Dates<=A2,IF(Names<>"",MATCH(Names,Names,0)))),ROW(Names)-MIN(ROW(Names))+1),1))
Confirmed with CTRL+SHIFT+ENTER
Names and Dates should be the same size and as small as possible because the formula can be slow

Resources