I got some trouble with the SUMIFS function in Excel (2010). I want to make a sum of my hours per week, so I need a SUMIF. This is an example:
In F5 (and whole column F) is this function:
=IF(OR(A6="",WEEKNUM(A6,2)<>WEEKNUM(A5,2)),SUMIFS(E$2:E6,G$2:G6,"="&G5),"")
summing all values from E at the end of each week.
I would like to get rid of the extra column G that I need now, and use the WEEKNUM function instead. Then the function in F5 would look something like this
=IF(OR(A6="",WEEKNUM(A6,2)<>WEEKNUM(A5,2)),SUMIFS(E$2:E6,WEEKNUM(A$2:A6),"="&WEEKNUM(A5)),"")
but this example isn't working.
Any ideas?
You can't use any function to modify a range in SUMIFS.....and also I would say that WEEKNUM isn't best for this as you may get confusion between years; and also weeks at the start/end of the year may not have 7 days (because week 1 always starts on 1st Jan whatever the day of the week - according to how WEEKNUM works anyway). You can use WEEKDAY function more easily, e.g. in F5
=IF(OR(A6="",A5-WEEKDAY(A5,3)<>A6-WEEKDAY(A6,3)),SUMIFS(E$2:E5,A$2:A5,">="&A5-WEEKDAY(A5,3)),"")
That uses WEEKDAY to find the previous Monday and sums anything that is in the last week based on that - so this will work even through Dec/Jan
Related
I have a excel spreadsheet with two columns. One with a date and another with the value.
I want to get the working day of the month with the lowest value.
I tried to use a pivot table for it and then group the date but I get a lot of errors.
You can find the spreadsheet here and the sheet name is Historical. The others are just attempts made by me.
Spreadsheet
Thanks
The formula entered in E2 below
is
=AGGREGATE(15,6,(POWER(10,LOG10(((YEAR(D2)=YEAR($A$2:$A$3254))*(MONTH(D2)=MONTH($A$2:$A$3254)))))*$B$2:$B$3254),1)
and the array formula entered in F2 below is
=INDEX($A$2:$A$3254,MATCH(YEAR(D2)&MONTH(D2)&E2,YEAR($A$2:$A$3254)&MONTH($A$2:$A$3254)&$B$2:$B$3254,0))
I suggest to make an triple nested if-construct that checks if the weekday of the date is a workday, or the date+ 1 or the day +2. Assuming the date is in cell A4
= if(instr(weekday(A4),”23456”)>0, A4,
if(instr(weekday(A4+1),”23456”)>0, A4 + 1,
if(instr(weekday(A4+2),”23456”)>0, A4 + 2,”cannot happen”)))
Explanation: one of 3 consecutive days is always a working day.
There may be typos since I edit that on iPad without Excel available to test.
Weekday returns 1 for Sunday and 7 for Saturday. So 2-6 are workdays.
However with that simple approach you will not detect public holidays on a working day if that is a problem.
Hope I understood you question correctly. One data example with solution would have explained it better.
I have a series of dates and values:
8.12.2018 12
5.2.2019 32
15.7.2019 89
I would like to use something like (SUMIFS(YEAR(A1:A3);2018) but it's not allowed.
I know, I could extract the year in a separate column, but here I want to ask, if it's possible inside the sumifs function?
Although I thought you couldnt, it has proven by #forwardEd, you can alter criteria in such a way to use SUMIFS, however, you could also look into SUMPRODUCT for this exercize:
=SUMPRODUCT(--(YEAR(A1:A3)=2018),B1:B3)
Assuming your dates are valid excel dates and not dates as strings/text then you can use the SUMIFS formula for a year as follows:
=SUMIFS(B1:B3,A1:A3,">="&date(2018,01,01),A1:A3,"<="&date(2018,12,31))
Basically the formula is saying sum all the values in B1:B3 where the date in A1:A3 is greater than or equal to the first day of the year AND less than or equal to the last day of the year. I choose to write the date using the date function as it is easier to recognize than the integer format of the date. If you want to write just the year as a criteria in say cell c2 then replace 2018 in the above formula with c2.
UPDATE
I have not tested it but since the default for a date without time is 00:00:00 it would mean the formula above would cut off December 31 with almost any sort of time associated with it. Therefor the better cut off would be less than January 1st of the following year instead of less than or equal to December 31st. As such you could revise the above formula to:
=SUMIFS(B1:B3,A1:A3,">="&date(2018,01,01),A1:A3,"<"&date(2019,01,01))
or
Where C2 is the year as an integer
=SUMIFS(B1:B3,A1:A3,">="&date(C2,01,01),A1:A3,"<"&date(C2+1,01,01))
Alternative approach (a little bit less elegant solution, but might be more clear to less advanced users):
=SUMIFS(B1:B4,A1:A4,">="&"01/01/2018",A1:A4,"<="&"31/12/2018")
I am building a new dashboard that refreshes on a daily basis. The dashboard includes current month data as well as prior month data. However, I need to try a few different scenarios in terms of dates to ensure that month transitions work with no problem. For example, I would like to know what my formulas would do when it is the first day of the month, and the second day of the month with different conditions such as the 1st day being weekends or holidays, etc, where I won't have any data, which would lead to errors.
I tried fixing formulas, but there were way too many formulas involved and related to each other. Also data is being pulled from SQL server, where I am also using GETDATE().
For example, one of my formulas show
=YEAR(TODAY()-1)&IF(MONTH(TODAY()-1)<10,0&MONTH(TODAY()-1),MONTH(TODAY()-1))
to get the year & month (e.g. 201904 for 2019 April). This is one of many formulas that has today() built in
In sum, I am wondering if I can change the date that Excel is reading off. For example, I have a formula with =TODAY() - I want this formula to return some other days I set to, rather than actual date of today.
First place this user defined function in a standard module:
Public Function todaz() As Date
todaz = Evaluate("=today()") + 12
End Function
Then in your worksheet, replace all instances of:
Today()
with:
todaz()
You can change the User defined function to have any date offset you wish.
When you are done testing, change all the todaz() back into Today().
Here's a non-VBA version:
Have a cell in which you put just =Today(). In the worksheet, replace all other instances of Today() with a reference to this cell. For testing, replace the Today() with whatever date you like, and when you're done, put the Today() back in.
Both this and Gary's Student's version have the advantage of being less volatile - that is, they will run much faster because Today() is one of those functions that recalculates frequently in every place it appears -- and in your case that sounds like a lot.
I'm trying to count rows where the date in a Date column falls within a particular month. I've tried many paths but all result in an error in my formula. They boil down to me trying to do this:
=countIF(Month(SHData[#MS550]),MONTH(SHData[#MS550]))
My final formula will need to be more complex than that, but even something as simple as the above generates an error. I've also tried it with Text(Date,"MMMM") with the same results.
Would be easier with COUNTIFS but with COUNTIF you might count all the entries greater than or equal to the start of your chosen month, then subtract from that the count of all the entries after the end of your chosen month. Something like:
=COUNTIF(SHData[MS550],">42004")-COUNTIF(SHData[MS550],">42036")
for January this year, if using the 1900 date system.
Try using SumProduct, this just worked fine for me with a column of dates testing if they were in September:
=SUMPRODUCT(--(C3:C5>0),--(MONTH(C3:C5)=9))
How do I set one day before today; for example I would like a warning the day before a birthday..
=IF(C10=TODAY(),HYPERLINK("mailto:"&D10&"?subject="&$C$4&"&body="&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($C$5,"$",B10),"#",$C$6),CHAR(10),"%0A"),"Send mail"),"")
Excel stores dates as numbers. You can easily do simple maths with dates, like adding or subtracting days. A day is 1. Seven days is 7.
Today() is a function that returns the current date. To get yesterday's date, subtract a day from Today() like =Today()-1. To get tomorrow's date add a day to Today() like =Today()+1.
This arithmetic can also be applied inside of more complex functions. The formula in your question looks at Today() and compares it to C10. If you want the same functionality if the date in C10 is "tomorrow", you nee to add a day to Today().
That's what Jeeped's comment means.
=IF(Today()+1=C10,[the rest of your formula]