Excel Formula with Date from other cell - excel-formula

I count the number of Excel entries within a date with the following formula (ZÄHLENWENN = COUNTIF)
=ZÄHLENWENN('2021'!L:L;">=01.11.2021")-ZÄHLENWENN('2021'!L:L;">30.11.2021")
The Formula here is working but since I don't want to enter the date values ​​for every month of the year I have created a calculation with the function end of the month. (MONATSENDE)
How do I have to rebuild the formula when I get the two dates from two cells?
Cockpit E3: =MONATSENDE(D3;-1)+1 -> shows 01.11.2021
Cockpit F3: =MONATSENDE(D3;0) -> shows 30.11.2021
Cockpit D3: =01.11.2021 (the only one entered manually)
Unfortunately the outcome of my new formula is 0:
=ZÄHLENWENN('2021'!L:L;">=Cockpit!E3")-ZÄHLENWENN('2021'!L:L;">Cockpit!F3")
What did i do wrong ?
Greetings

You have to put E3 and F3 as references to the formula - not as a string:
=ZÄHLENWENN('2021'!L:L;">=" & Cockpit!E3)-ZÄHLENWENN('2021'!L:L;">" & Cockpit!F3)
Tip: apply a name to E3 and F3 (e.g. FirstOfMonth, EndOfMonth) and then use the names within the formula. It then gets more "readable" - also for someone else who might maintain the project later.
=ZÄHLENWENN('2021'!L:L;">=" & FirstOfMonth)-ZÄHLENWENN('2021'!L:L;">" & EndOfMonth)
And maybe you should consider using tables for sheet 2021 (Einfügen > Tabelle)

Related

Can you define names for dates in Excel to use them in formulas?

I hope you are all well.
I have a question. I have a list with many payments listed on column A with dates (format day/month/year) in column B and I would like to use a formula which says something like
IF= A1 = Q2, "pay", "don't pay" , IF= A2 = Q2, "pay", "don't pay"...
Q2 means quarter 2
Could I define names for dates? For example Q2 would be 01/04/2021 - 30/06/2021 so all the dates within that range would be named Q2.
Best regards
You may try anyone of the approaches as explained below, the first one is using ROUNDUP & MONTH Function and the other one is using DEFINED NAMES.
First Approach ---> Using ROUNDUP & MONTH FUNCTION
• Formula used in cell B3
="Q"&ROUNDUP(MONTH(A3)/3,0)
• Formula used in cell C3
=IF("Q"&ROUNDUP(MONTH(A3)/3,0)="Q2","Pay","Don't Pay")
So you can see i have used two columns in the first approach just to make it understandable, therefore just wrap the formula in cell B3 within an IF logic as shown in cell C3 to get the desired output.
Second Approach --> Using DEFINED NAMES & SUMPRODUCT FUNCTION
• Formula used in Defined Names
=ROW(INDIRECT(--TEXT("01-04-2021","dd/mm/yyyy")&":"&--TEXT("30-06-2021","dd/mm/yyyy")))
So you can see I have Defined the Quarter 2 as _Q2 and the reason is a name must either begin with a letter, underscore (_), or backslash (). If a name begins with anything else, Excel will throws an error.
Therefore the formula used in cell D3
=SUMPRODUCT((A3>=_Q2)*(A3<=_Q2))
The above formula creates an array of TRUE's & FALSE's and multiplies to return the corresponding values.
Now the above formula when wrapped within an IF Function it gives us the requisite output as desired,
Formula used in cell E3 (Same it can be done in one cell, to make it understandable i have used two columns)
=IF(SUMPRODUCT((A3>=_Q2)*(A3<=_Q2))=1,"Pay","Don't Pay")
So this is how you can used a Defined names for dates in excel and then use the same within a formula.
This solution does not provide names for dates but it might meet your needs:
Make sure column A is formatted as a date, then use this formula to get the quarter from the month (this array allows you to set Q1 if it is not the same as calendar quarters):
="Q"&CHOOSE(MONTH(A1),1,1,1,2,2,2,3,3,3,4,4,4)
Then test the value of this column:
=if(C1="Q1", "Pay", "Do not Pay")
You could also create a cell at the top of your spreadsheet and name it current_quarter. Then you would type in the current quarter "Q1", "Q2", ... and your formula would be
=if(C1= current_quarter, "Pay", "Do Not Pay")
You are using standard calendar month quarters, so we can get the quarter number easily by dividing and rounding up.
=ROUNDUP(MONTH(A1)/3,0)
You can then use this number in your IF function.
=IF(ROUNDUP(MONTH(A1)/3,0)=2,"Pay","Don't Pay")

VLOOKUP against helper column with date formatted as text?

I'm using a vlookup against a table that has a generally-formatted column in the format "WORD NUMBER DATE" such as "Romeo 5M 06/16/2019". The reference is a helper column that I've created combining "Romeo" and "5M" and "06/16/2019". However, the date part needs to be formatted as text or else it won't match the lookup. This formatting is causing the #N/A error, despite a match. When I use =cell=cell2, it brings up "FALSE", given the formatting.
Help with this?
Thanks in advance.
I've already tried copy/paste formatting, and typing out the text in the cell makes the reference work so I'm assuming it's the formatting.
You can format the date in three separate cells. Assuming your date is in cell A1:
In Cell B1 - get the Year value
=YEAR(A1)
In Cell C1 - change the value to 2 digits if the month value is only 1:
=IF(LEN(MONTH(A1)) = 1, "0" & MONTH(A1), MONTH(A1))
In Cell D1 - change the value to 2 digits if the day value is only 1:
=If(LEN(DAY(A1)) = 1, "0" & DAY(A1), DAY(A1))
Then, in your aggregation formula, combine them like this:
= C1 & "/" & D1 & "/" & B1
If I'm reading your question correctly this should solve your issue.
Alternatively, if you need to change the cell format to text you may need to use vba code to perform some calculations for you which I can outline for you as well if this solution doesn't help you.

How to find minimum and maximum values in Column B based on a specific string in column A?

I have a list of items in Column A and have corresponding year and month values in Column B and C respectively. I am looking to find the minimum and maximum year in Column B (based on specific value in Column A), then find the corresponding month in Column C (only for max and min value) and then generate and fill in a Start and End date in Column E and F respectively.
E.g. IF #Item = Laptop THEN FIND MIN,MAX of #YEAR and THEN FIND adjacent value in #Month. Finally formulate and display a date accordingly.
Could i achieve this using a formula or is it out of scope and is better achieved using a macro?
For the Start date, in E2:
=IF(A2<>A1,DATE(AGGREGATE(15,6,$B$1:$B$1000/($A$1:$A$1000=A2),1),AGGREGATE(15,6,$C$1:$C$1000/(($A$1:$A$1000=A2)*($B$1:$B$1000 = AGGREGATE(15,6,$B$1:$B$1000/($A$1:$A$1000=A2),1))),1),1),"")
And for the end date in F2:
=IF(A2<>A1,EOMONTH(DATE(AGGREGATE(14,6,$B$1:$B$1000/($A$1:$A$1000=A2),1),AGGREGATE(14,6,$C$1:$C$1000/(($A$1:$A$1000=A2)*($B$1:$B$1000 = AGGREGATE(14,6,$B$1:$B$1000/($A$1:$A$1000=A2),1))),1),1),0),"")
Then copy down the desired rows.
The aggregate function was introduced in 2010 so it will not work in excel 2007 or earlier.
I over thought they can be simplified to:
=IF(A2<>A1,AGGREGATE(15,6,DATE($B$1:$B$1000,$C$1:$C$1000,1)/($A$1:$A$1000=A2),1),"")
And:
=IF(A2<>A1,AGGREGATE(14,6,EOMONTH(DATE($B$1:$B$1000,$C$1:$C$1000,1),0)/($A$1:$A$1000=A2),1),"")
Thanks to #Jerry for showing a more succinct method.
Here is something that I think should work for any version of Excel, and thanks to the comment from #ScottCarver you can now copy it down and it will put the dates on the first row of each Item:
Enter this in E2 as an array formula and then copy down:
=IF(A2<>A1,MIN(IF(A:A=A2,DATE(B:B,C:C,1))),"")
Enter this in F2 as an array formula and then copy down:
=IF(A2<>A1,MAX(IF(A:A=A2,DATE(B:B,C:C+1,0))),"")
Because these are array formulas you need to press control-shift-enter instead of just enter. After they are entered they will be surrounded by { } to indicate that they are array formulas.
Original Answer:
Here is something that I think should work for any version of Excel, but you can't copy it down - you have to enter one separately for every Item. If you really want them spread out so that the dates are on the row of the first occurance of the Item (like in your screenshot) then this won't really work for you.
For the start date of the Laptop Item:
=MIN(IF(A:A="Laptop",DATE(B:B,C:C,1)))
For the end date of the Laptop Item:
=MAX(IF(A:A="Laptop",DATE(B:B,C:C+1,0)))
These are array formulas so you need to press control-shift-enter instead of just enter. After they are entered they will be surrounded by { } to indicate that they are array formulas.

Can I use changing variables in Excel formulas

I have several worksheets with data that changes each month in new rows. After entering all of the data, I run various analyses that pull specific data from the worksheets. For example, one such analysis looks like:
=MeterReadings!K27-MeterReadings!K26
The columns ("K") do not change, but the rows increase by one each month.
Is there a way that I can simply specify a new row number-- e.g. "x" and "y" -- and have all of the analysis formula automatically regenerate.
Current month: x= 27
Prior month: y= 26
Then
=MeterReadings!K"x"-MeterReadings!K"y"
What you're looking for is the INDIRECT function. It allows you to create a cell reference from a regular string of letters and numbers. Your example might go something like:
=INDIRECT("MeterReadings!K" & CountA(K:K)) - INDIRECT("MeterReadings!K" & CountA(K:K)-1)
Lets assume that the cell a1 is for the value x and cell b1 is for value y,
On c1 enter:
=INDIRECT("MeterReadings!K"&B1)-INDIRECT("MeterReadings!K"&B2)

Get date value based on month name

The scenario I have is as follows:
Cell A1 - contains the name of the current month, e.g. "October"
Cell A2 - contains the value of the current year, e.g. "2014"
Cell A3 - contains the value of a given day, e.g "22"
I'd like to populate A3 with a formula that will give it the value 22 October 2014 and have this formatted as a date so I can perform comparisons and calculations in other cells - so along the lines of 22 + A1 + A2. I've tried using the CONCATENATE function but this doesn't let me format the cell as a date.
Is something like this even possible using the standard Excel functions?
You're looking for the DATEVALUE function. It can convert month names into a numerical date expression, which you can then format as a date (dd/mm/yyyy in the example below).
=DATEVALUE(A3 & " " & A1 & " " & A2)
As a bonus, this will also work if A1 contains short-form month names i.e. Jan, Feb, Mar, etc.
I just did a bit of testing, which showed that you can also drop the " " space delimiters entirely:
=DATEVALUE(A3&A1&A2)
In fact, just using -- to force Excel to treat the concatenated string as a numerical value works as well!
=--(A3&A1&A2)
So far, my testing has not found any instance where -- doesn't work as well as DATEVALUE. Leaves me wondering what the point of DATEVALUE is.
Try this:
=DATE(A2,MATCH(A1,{"January","February","March","April","May","June",
"July","August","September","October","November","December"},0),A3)
You can also use this formula
=(A1&A2)+A3-1
format result cell in required date format

Resources