I have this formula as a conditional format that highlights certain cells that meet the date requirements. I just want to add an extra criteria that highlights as well if the date=today. Seems simple but I cannot get the syntax right.
Can anyone help, please?
Current Formula:
=AND(ISNUMBER(SEARCH("Condo",K11)),OR(AND(WEEKDAY(TODAY())>= 3,WEEKDAY(TODAY())<=6,INT(X11)=INT(TODAY()-1)),AND(WEEKDAY(TODAY())=2,INT(X11)>=INT(TODAY()-3),INT(X11)<=INT(TODAY()-1))))
First off, consider this topic for basic examples of how to review your own code, may come in handy in future! ☺. You can find this post here.
Google Sheets: here
Screenshot
Component | assessment
(note: my column E represents what you have in column X, and likewise my column F is what you 'appear' to have in K).
Function
Interpretation, possible issues/remedy
1. K11 includes 'Condo'
Case of word (try: search("condo", lower(K11)) etc. to mitigate errors if case is unimportant
2. Weekday
Weekday(today()) defaults to 1 if today() = Sunday. If you're expecting 7 instead, use weekday(date,2).
AND{3-4} where:
3. OR - first 'AND'
3a. WEEKDAY(TODAY())>=3
Weekday ('today()') = Tue-Fri (incl.) F3 must be day before
4. OR - second 'AND'
4a. WEEKDAY(TODAY())=2
Weekday (today) = Mon AND
4b. INT(F3)>=INT(TODAY()-3
F3 must be Sun
Conclusion:
a) Suspect you were intending to be using Weekday(date,2)
b) Default for 'weekday(date)' returns following weekdays:
c) HOWEVER, judging from the 2nd AND statement:
INT(F3)>=INT(TODAY()-3)
includes possibility of having negative weekdays(!)
d) fyi : you don't need to include 'INT' everywhere, you should be able to simply reference the dates, Excel will figure out the rest (i.e. will automatically use serial code when taking differences, adding 3 days etc.).
Related
I am searching for a formula solution that would summarize hours based on two conditions (date - column a, activity - column b). More precise, I want to summarize hours of sleep each day with array formula that would include whole column range.
The data looks like this:
When I define exact range the formula works.
{=IF(A2:A10=I$6;IF(B2:B10="Sleep";(D2:D10)-(C2:C10);0);0)}
But when I try to include whole column it returns 0.
{=IF(A:A=I$6;IF(B:B="Sleep";(D:D)-(C:C);0);0)}
Thank you!
You can use the entire column using an IF statement inside SUM or SUMPRODUCT. It ensures the time differences is only carried out on valid rows of the input data:
=SUM(IF(($A:$A=F1) * ($B:$B="Sleep"), ($D:$D + ($C:$C > $D:$D) - $C:$C),0))
Then just extend the formula to the right (notice the $-notation).
Using SUM or SUMPRODUCT directly produces an error (#VALUE!), for example:
=SUM(($A:$A=F1) * ($B:$B="Sleep") * ($D:$D + ($C:$C > $D:$D) - $C:$C))
because it doesn't filter first for valid rows where the subtract doesn't produce an error.
Here is the output:
Note: You need to try for your excel version, for O365 it works, but it has to be tested for an older version.
The calculation for time differences (the parenthesis is required):
$D:$D + ($C:$C > $D:$D) - $C:$C
Ensures that when the end date represents a time from the next day as it is in row 5, it adds 1, to consider the next day. You can achieve the same using another IF (longer but may be easier to understand):
IF($D:$D > $C:$C, $D:$D - $C:$C, (1+$D:$D) - $C:$C)
Performance: Please keep in mind #JosWoolley comments below, about performance. Usually, indicating the entire column in the formula instead of a specific range, forces Excel to check all rows (current maximum: 1,048,576). No significant impact for invoking the formula just one time, but for multiple invocations, it will be a significant impact on performance or Excel can even not respond.
Take a look at this link for some little-known insight from Microsoft. Microsoft deliberately prevents the use of entire columns in some formulas that internally use arrays:
Excel Limitations
In particular, see this paragraph.
If you designate your data as an Excel table then you could use structured referencing, as in the example below
=SUMPRODUCT(((Schedule[End]+(Schedule[Start]>Schedule[End]))-Schedule[Start])*(Schedule[Activity]="Sleep")*(Schedule[Date]=I6))
but you should recognise that the organisation of your data does not permit the (by-date) analysis you require, e.g. most of the sleep attributable to Jan 22nd is properly attributable to Jan 23rd but that can't be reflected in the summary, as you have treated the end time on Jan 22nd as being 16 hours before the start time...
(cells I7:K7 have the custom number format [hh]:mm)
I have two excel spreadsheets and want to write a code that uses vlookup, match, and if such that when run it will check to see if there is a match between the price of the transaction and rate of the contract for each "contract agreement id" and if there is not a match it will turn the font on that row to red. For example rows 3, and 9 on the transaction page will turn red because either the price/rate does not match or there is not a contract for that transaction BUT row 9 on the contracts page is okay because you can have a contract without a transaction.
Screenshots refer,
Assumptions:
Noting - some ambiguity in the Q - I make these assumptions:
You actually intend to compare "Price" (col I, 1st pic) to "Rate" (col H, 2nd pic) for common contract IDs and expiry dates (as these are the only two factors by when Price/Rate differs in respective sheets/tables).
If this is not the intention, then it should be an easy exercise to modify the lookup / matching criteria to the precise definition of correspondence desired (days/burger size/description whatever)
Base fn
formula - basic function underpinning conditional formatting function:
=IF(--ISNUMBER(MATCH(H4:H9&I4:I9,C4:C9&D4:D9,0)),J4:J9-E4:E9,"no match")
Conditional formatting equations:
For different prices (yellow) - assuming a matched contract ID and expiry date:
=--(1*ABS(IF(--ISNUMBER(MATCH($H4:$H9&$I4:$I9,$C4:$C$9&$D4:$D9,0)),$J4:$J9-$E4:$E9,"no match"))>0)
For equal prices (assuming match):
=(IF(--ISNUMBER(MATCH(H4:H9&I4:I9,C4:C9&D4:D9,0)),J4:J9-E4:E9,"no match")=0)
For some reason conditional formatting equations do not appear to preserve the 'array' output - i.e. whereas you wouldn't ordinarily need to 'fix' ranges for 'spill'-type functions, you do now when using conditional formatting - just select range and press F4. fyi
Paint entire region gray to begin with (process of elimination means that no equation required for this option 'no match').
Note: in my example expiry dates were set to not necessarily match. In your sample data - I see there is a 1:1 match - this means you should be fine applying my formula as is / with minimal aleration (you would want to have this second condition because rates for the same product otherwise appear to vary according to expiry - if this is what you intend to determine then I recommend using an averageifs with everything else as is, if quantum is of interest - however, per one of the comments, you may only require a binary 'countifs' equation - notwithstanding the requirement for a second condition as part of the primary lookup key - if that makes sense...)
I wondering if anyone will be able to help me sort the formula below out:
=IFERROR((VLOOKUP($D96,August!$C:$P,F$78,FALSE))-(VLOOKUP($D96,July!$C:$O,(F$78+1),FALSE)),IF(U96="NEW PART",(VLOOKUP($D96,July!$C:$O,(F$78+1),FALSE)),IF(V96="NEW PART",(VLOOKUP($D96,August!$C:$O,(F$78),FALSE)),"")))
Originally the formula was
=IFERROR((VLOOKUP($D95,August!$C:$P,F$78,FALSE))-(VLOOKUP($D95,July!$C:$O,(F$78+1),FALSE)),"BLANK")
However rather than returning "BLANK" if either sheet does not include that part number I would like the formula to return the figure on the one sheet they appear on. Columns U and V highlight weather the product number is on each sheet. These figures would be + figures if they appear in august and minus figures if they appear in July.
Link/screenshot refer:
In short - replace final 'FALSE' with an additional iferror(Aug,-July)
(see revision at end, following comments / feedback re sound applications/customizing soln as required)..
Formula - per OP request
=IFERROR(VLOOKUP(H4,B4:C14,2,FALSE)-VLOOKUP(H4,E4:F14,2,FALSE),IFERROR(VLOOKUP(H4,B4:C14,2,FALSE),-VLOOKUP(H4,E4:F14,2,FALSE)))
Improvised version
(pre-requisite: Office 365 compatible version of Excel)
=LET(A,INDEX(C4:C14,MATCH(H4#,B4:B14,0)),B,INDEX(F4:F14,MATCH(H4#,E4:E14,0)),IFERROR(A-B,IFERROR(A,-B)))
Motive
Arguments in favour of this version include:
OP version: 127 chars (vs 104) i.e. ~20-25% length reduction on this basis
Audit/review - arguably easier given let function
Flexibility: unless you plan to take advantage of vlookup 'approximate matching' (using True flag instead of False), Index more robust in that it can handle forward and backward references in relation to the indexed column (i.e. with vlookup, index has to lie to left of the column comprising the cell to be returned)
The usual benefits assoc. with 'spill' ranges (i.e. potential for 'dynamic' range feature and automatic calc. from single cell entry)
REVISION:
The following screenshot should shed some light on references/ranges you may wish to alter for 1st formula in present response to operate as you intend within your workbook (corresponding ranges are colour-coded with clear visual link between each)...
So to apply in your case, you'd need to replace shaded/boxed ranges/references in my proposal with those you're using (as indicated - i.e. replace by H4 with your $D95 etc,..."
JB: replace final 'FALSE' with an additional iferror(Aug,-July)
This concept is clearly delineated within screenshot above.
OP: "I tried and just got N/A"
As link in opening line provides evidence of two alternative solns. working error-free, presume 'n/a' result of incorrect application...
I just found out how to lookup a date within a range of dates (source: https://www.mrexcel.com/forum/excel-questions/621562-vlookup-if-date-between-2-dates-table.html)
Although, I cannot seem to find any documentation on how =lookup() searches both columns. Can someone please explain how it works?
Please see below for the formula, and example data.
Formula:
=LOOKUP(b1,$a$5:$b$7,$c$5:$c$7)
Example:
Lookup 9/10/2017
Result Week 2
Week Start Week End Week Number
27/09/2017 3/10/2017 Week 1
4/10/2017 10/10/2017 Week 2
11/10/2017 17/10/2017 Week 3
Okay, after 1 more google search - I've found the answer (and in the place I really should have looked first):
https://support.office.com/en-us/article/LOOKUP-function-446d94af-663b-451d-8251-369d5e3864cb
The above says: =lookup() can use either a vector syntax or an array syntax.
If you input an array to search - it uses the largest value in the array that is less than or equal to lookup_value. Based on testing - it matches the row based on this (and will search both columns to find a value). E.g. If the first column of data is deleted, and you lookup a date that preceeds 03/10/2017, it will return "#N/A", if the first column is not deleted, that search will return "Week 1".
Not sure if I should delete this question - seeing as this is well documented in the microsoft office docs - if someone could please let me know if that's best thing to do or not that'd be much appreciated.
Background is that I'm making a budget spreadsheet. I have different bills due on different days. (ie. bill due on Monday and bill due on the 10th)
I want a function that will place the appropriate amount of money going in/out in column D and the description of why the money is going in/out in column E.
Currently I have two different formulas that I created (probably incorrectly).
Formula for Column E: (Already is in the document and seems to work fine other than that fact that I cant add additional text to the cell)
=IF(DAY(C36)=7," Amy Pay","")&IF(DAY(C36)=22," Amy Pay","")&IF(DAY(C36)=8," Family Bills","")&IF(DAY(C36)=6," Dollar Shave Club","")&IF(DAY(C36)=2," Amy Cap One VISA","")&IF(DAY(C36)=3," Chase VISA","")&IF(DAY(C36)=8," Being Smart","")&IF(DAY(C36)=17," Gym","")&IF(DAY(C36)=11," Netflix","")&IF(DAY(C36)=19," Cap One MC","")&IF(DAY(C36)=29," CenturyLink","")&IF(DAY(C36)=6," Haley Cap One Visa","")&IF(DAY(C36)=10," SRP","")&IF(DAY(C36)=23, "Car Payment","")&IF(DAY(C36)=30, "Rent","")&IF((B36)="Mon"," Monday","")&IF((B36)="Fri"," Friday","")&IF((B36)="Fri"," Haley Pay","")
Formula for Column D: (not in the column yet, as it doesn't work how I want)
=IF(DAY(B40)=7,"1474.22","")&IF(DAY(B40)=22,"1474.22","")&IF(DAY(B40)=8,"-100","")&IF(DAY(B40)=6,"-9","")&IF(DAY(B40)=2,"-100","")&IF(DAY(B40)=3,"-100","")&IF(DAY(B40)=8,"-400","")&IF(DAY(B40)=17,"-20.05","")&IF(DAY(B40)=11,"-8.63","")&IF(DAY(B40)=19,"-450","")&IF(DAY(B40)=29,"-50","")&IF(DAY(B40)=6,"-150","")&IF(DAY(B40)=10,"-200","")&IF(DAY(B40)=23,"-325","")&IF(DAY(B40)=30,"-500","")&IF((A40)="Mon","-125","")&IF((A40)="Fri","-325","")&IF((A40)="Fri","400","")
http://imgur.com/IBINweh
The problem is that in column D, rather than providing a sum of the numbers, it lists the numbers in the column.
http://imgur.com/rPDS5h2
I had a suggestion to add =SUM( in front of the IF( function, but when I do, #VALUE! is what results in the field. Using this formula: (view image by changing appended text to /CVs0f1v )
=SUM(IF(DAY(B40)=7,"1474.22","")&IF(DAY(B40)=22,"1474.22","")&IF(DAY(B40)=8,"-100","")&IF(DAY(B40)=6,"-9","")&IF(DAY(B40)=2,"-100","")&IF(DAY(B40)=3,"-100","")&IF(DAY(B40)=8,"-400","")&IF(DAY(B40)=17,"-20.05","")&IF(DAY(B40)=11,"-8.63","")&IF(DAY(B40)=19,"-450","")&IF(DAY(B40)=29,"-50","")&IF(DAY(B40)=6,"-150","")&IF(DAY(B40)=10,"-200","")&IF(DAY(B40)=23,"-325","")&IF(DAY(B40)=30,"-500","")&IF((A40)="Mon","-125","")&IF((A40)="Fri","-325","")&IF((A40)="Fri","400",""))
Any ideas on how I can get all the to populate and sum appropriately?
Forgive my Non Excel Guru knowledge - trying to learn. :D
-Amy
If you take all of the options from your first working formula and change the method retrieving them, you will have a much more versatile worksheet that can easily accept new additions and schedule modifications.
In a couple of unused columns to the right, pit in the day-of-month and the action that occurs. I'm using columns Y & Z. You have two events occurring on the 6th so I put them together.
In a couple of other unused columns use the day-of-the-week and associated text.; I've used columns V & W. The default for Sunday is 1.
In E36 use this formula, =TRIM(IFERROR(VLOOKUP(DAY(C36),$Y:$Z, 2, FALSE), "")&" "&IFERROR(VLOOKUP(WEEKDAY(C36),$V:$W, 2, FALSE), ""))
Fill down as necessary.
If you want the day-of-the-week in column B, use =C36 and use a custom number format of ddd or dddd.
References:
VLOOKUP function WEEKDAY function
You are concatenating text strings that look like numbers. You probably want to be adding real numbers:
=SUM(IF(DAY(B40)=7,1474.22,0) + IF(DAY(B40)=22,0) + ...
although, whenever I see a formula as complex as what you have, I would consider looking for a different solution -- Vlookup comes to mind.
In addition, with a VLOOKUP table, you would have seen that you have some conflicts -- e.g: you list the same condition of B40=8 to return two different values; and the same condition of A40 = Fri, to also return two different values.