I have this table of currency rates:
I would like to create a formula that receives the begin date and end date + currency, and in return will calculate the average for every month inside the range.
For example, if the currency is GBP, begin date is 15/09/2015 and end date is 20/11/2015, I would like to calculate averages for 30/09/2015 + 31/10/2015 + 30/11/2015.
I tried to solve it with a simple Average + Vlookup + Match functions, but it wouldn't get me the range of cells but only the edges of the range. I also thought of using AverageIF function, but I'm not sure how to combine between the criterias of date and currency.
Can you think of an easy way to solve that?
I suggest using an index/match to get a reference to the beginning of the range of currencies then another one to get the end of the range and combining them like this:-
=AVERAGE(INDEX($B$2:$H$10,MATCH(D13,A$2:A$10,0),MATCH(1,(MONTH(E13)=MONTH($B$1:$H$1))*(YEAR(E13)=YEAR($B$1:$H$1)),0)):
INDEX($B$2:$H$10,MATCH(D13,A$2:A$10,0),MATCH(1,(MONTH(F13)=MONTH($B$1:$H$1))*(YEAR(F13)=YEAR($B$1:$H$1)),0))
)
Where the currency name is in D13, start date in E13 and end date in F13, and the table is in A1:H10.
Result: 1.5203
Must be entered as an array formula using CtrlShiftEnter
Found a way to solve this, by using the AVERAGEIF function. Enjoy, and thanks for helping!
Related
How can I check if an input_date falls between two dates (a date range) in excel, where the date range exists in a list of date ranges?
So I need to check if input_date falls between any date range, and then if it does, return the value of the date ranged it matched with. See the below table for an example.
Month
Start Date
End Date
Month 1
1/1/2022
1/31/2022
Month 2
2/1/2022
2/27/2022
Month 3
3/1/2022
3/31/2022
Input vs Expected Result
input_date
Expected Result = Month
1/25/2022
Month 1
2/3/2022
Month 2
I've tried using =IF(AND(A2>StartDate,A2<EndDate),TRUE, FALSE) but how can I check A2 against all date ranges in a list, and output the corresponding Month value? Is the best way really just nesting if statements for a fixed number of ranges? Any dynamic approach?
You may try using the either of formulas like shown below,
• Formula used in cell B7
=XLOOKUP(1,(A7>=$B$2:$B$4)*(A7<=$C$2:$C$4),$A$2:$A$4,"")
If one do not have access to XLOOKUP() then INDEX() & MATCH() can also be used,
• Formula used in cell C7
=INDEX($A$2:$A$4,MATCH(1,(A7>=$B$2:$B$4)*(A7<=$C$2:$C$4),0))
If you just require the text output of the month the input date is referring to then can you not just:
=TEXT(A2,"mmmm")
Or do you have a need for something outside of your example?
You can use the FILTER function to return the appropriate item from the "Month" column
If your Date Ranges are in a table named dateRange & the Input_Dateis inG2`:
=FILTER(dateRange[Month],(G2>=dateRange[Start Date]) * (G2<=dateRange[End Date]))
Note: I am putting this question as Excel and Google Docs as they have a ton of overlap for simple questions like this.
I have two columns of data. A date of a purchase and how much that purchase was for.
A B
11/23/2015 $59
12/5/2015 $23.32
1/21/2016 $12.09
1/22/2016 $78.21
1/22/2016 $5.88
2/14/2016 $0.13
... ...
(thousands of rows below this)
I want to SUM the amount of money spent on Mondays, Tuesdays, Wednesdays, etc.
If I use SUMIF, I run into this problem:
=SUMIF(A:A, WEEKDAY(A:A), B:B)
^ WEEKDAY only takes in a single date value.
I do not want a function that I have to drag downwards.
How would I accomplish this?
Try this query function:
=QUERY({A:B},"select dayOfWeek(Col1), sum(Col2) where Col1 is not null group by dayOfWeek(Col1)")
In this formula I used Array {A:B} and notation Col1, Col2... in the formula because now when you add new columns, the formula won't fail.
And the similiar formula, using sumif:
={arrayformula(unique(weekday(A:A))),arrayformula(sumif(weekday(A:A),unique(weekday(A:A)),B:B))}
In Excel you do it with this Array formula. Array formula needs to be entered with Ctrl-Shift-Enter.
{=SUM(IF(WEEKDAY($A$2:$A$1000,1)=E2,$B$2:$B$1000,0))}
This assumes your day of week in number is E2. The second parameter in Weekday function defines how you number the days of Week. Here I have used 1 which means 1 = Sunday and 7 = Saturday
I'm trying to determine the median of a set of data for each weekday. Currently, the data is in two columns, date and value. Some of the value rows are blank, as the data to be analyzed hasn't be entered yet. I've had a look at the median-if array formula, but when I combine it with Weekday function I just get an error
{=Median(if(Weekday('Data'!A:A)=1, 'Data'!B:B)}
This is the current formula I'm working with to calculate the median value for Sundays, and all I get out of it #VALUE!.
Copying a Comment from #sous2817:
Rather than use a whole column reference, you should just use the range you want to evaluate for the calculation. If you have something other than a date in Column A, it will throw the #Value error.
I have a column, G, with several dates in it, and another column, K, with several percentage values between 0 and 100%.
I also have an UDF, IsoWeekNumber, which returns the weeknumber for any given date.
What I want to do is have weeks 1 to 53 in N3:N55, and then have a formula in the column next to it counting how many of the entries for a given week aren't 100%. I've come up with this formula, but it seems that it gets the weeknumber for cell G3 only when doing the comparison.
=COUNTIFS($G$3:$G$649;IsoWeekNumber(G3)&"="&$N$3;$K$3:$K$649;"<>"&1)
So, is there any way to make the function inside the countif apply to each of the cells I am comparing? Is there a better alternative approach?
Addendum: UDF code from OP's comments -
Public Function IsoWeekNumber(InDate As Date) As Long
IsoWeekNumber = DatePart("ww", InDate, vbMonday, vbFirstFourDays)
End Function
Try using SUMPRODUCT((ISOWEEKNUM($G$3:$G$649)=N3)*($K$3:$K$649<>1))
Here's what I'm looking for....
Trying to Sum the count of worksheet 'Results 2013' column G items
IF Cell A matches "Canada"
IF Cell E (date) is July
Having trouble with the date portion of the SUMIFS statement below.
SUMIFS('Results 2013'!$G$2:$G$510,'Results 2013'!$A2:$A$510
,"=Canada",'Results 2013'!$E2:$E510,MONTH('Results 2013'!$E2:$E510)=7)
Example value of "Results 2013"$E$480 is
I try this formula, and it provides back "January" which is obviously incorrect.
=TEXT(MONTH('Results 2013'!$E$480),"mmmm")
However, this formula, results in TRUE or 1
=IF(MONTH('Results 2013'!$E$480)=7,1,0)
The simplest solution is to add a column Month using the MONTH function to compute values, and then refer to this new column in SUMIFS.
This tests whether the date values in column E fall within the range 7/1/2013 and 7/31/2013. If your dates all fall within 2013, it will work.
SUMIFS('Results 2013'!$G$2:$G$510,'Results 2013'!$A2:$A$510,"=Canada",
'Results 2013'!$E2:$E510,">="&DATE(2013,7,1),
'Results 2013'!$E2:$E510,"<="&DATE(2013,7,31))
This array formula will work with the more general case of dates falling within any year:
=SUM(G2:G510*(A2:A510="Canada")*(MONTH(E2:E510)=7))
You could use an array formula , then you can use month on the entire column:
{SUM(if('Results 2013'!$A2:$A$510="Canada",1,0)*if(MONTH('Results 2013'!$E2:$E510)=7,'Results 2013'!$G$2:$G$510,0))}
just remember to use ctrl+shift+enter rather than the usual enter to finish the formula