Is there a way to calculate a ratio using SUMIFs? - excel

I am trying to get cell I13 on sheet MONTHLY STATS - SPREADS to populate a 0 if there have been no L's to count between the dates of 1 Oct 21 and 31 Oct 21 on sheet SPREADS LOG.
But I only want this 0 to populate if there is data present in cell H13. If there is no data in H13I would like I13 to be blank. (note I cannot use a number format to hide these 0's in cell I13 as I am trying to average the complete I column )
Whilst it is doing this cell I13 must also be able to run the COUNTIFS & SUM formulas shown below.
This is the current formula in cell I13 :
=IF(SUM(COUNTIFS('SPREADS LOG'!P:P,{"L"},'SPREADS LOG'!R:R,">="&DATE(2021,10,1),'SPREADS LOG'!R:R,"<="&DATE(2021,10,31)))=0,"",SUM(COUNTIFS('SPREADS LOG'!P:P,{"L"},'SPREADS LOG'!R:R,">="&DATE(2021,10,1),'SPREADS LOG'!R:R,"<="&DATE(2021,10,31))))
If someone could tweak this formula, that would be great.

Related

Dynamic starting point of OFFSET and SUM formula

I have the following Excel spreadsheet:
A B C D E F G
1 Year 2015 2016 2017 2018 2019 2020
2 Revenue 5.000 4.000 6.000
3 Years to go back: 2
4 Sum of Periods: 10.000
In Row 1 you can find the years 2015 til 2020 and in Row 2 the corresponding revenue of each year.
In Cell C3 the user should input the number of years to go back and sum up the revenues. For example if the user puts in a 2 Excel goes back 2 years and sums up the revenue of 2017 and 2016 which is 10.000 in the case above. For this I used the following formula:
=SUM(OFFSET($E$2,0,-C3):$E$2)
This formula and the described calculation above work perfectly so far.
However, in 2018 I will have to adjust the starting point of Cell $E$2 in the formula above to Cell $F$2. Ohterwise the year 2018 will be excluded from the calculation.
=SUM(OFFSET($F$2,0,-C3):$F$2)
My question is now how can I avoid this permanent re-adjustment every year?
--> I think the solution should be a formula that identifies the first "non empty" cell within in a Row and then starts counting back the years from this cell. Somehow a combination of the SUM, OFFSET, ROW & COLUMN formula.
You may use this formula:
=SUM(INDIRECT("R2C" & (MATCH(YEAR(TODAY()),$1:$1,0) - $C$3 + 1) & ":R2C" & MATCH(YEAR(TODAY()),$1:$1,0), FALSE))
But be aware I'm assume the current year - $C$3 is within your data range.
Brief explain:
YEAR(TODAY()) - it will return the year of current date, then you don't need to re-adjust every year
MATCH(lookup_value, lookup_array, match_type) - it will find the value matched in first row, and return the index of cell
INDIRECT() - Form the result of match to a R1C1 notation, and convert the text to excel range
A simpler formula could be to use the 4th parameter of OFFSET to set the width and to calculate the starting point of the OFFSET using YEAR(TODAY()0-2016
=SUM(OFFSET($B$2,0,YEAR(TODAY())-$C$1,1,$B$3))
NON VOLATILE OPTION
Well non volatile if it were not for the TODAY() function. Replace TODAY() with a cell containing the starting year as a date. or replace Year(Today()) with a cell reference just containing the year (integer) and then it will be a non volatile option.
=SUM(INDEX($1:$1,MATCH(YEAR(TODAY()),$1:$1,0)):INDEX($1:$1,MATCH(YEAR(TODAY()),$1:$1,0)-($C$3-1))
Volatile functions recalculate every time something on the spreadsheet changes.
Non volatile functions only recalculate when something affecting them changes.
The index function returns the cell address with in the range its looking. for a 2D range you need to give row and column reference. For a 1D range, you only need to give find the position within the range.
Match finds a value within a given range.

Get user input for month and year to populate cells with dates of that month and year in excel

i want to take two inputs from user Year and month and then populate the cells with the dates of that month and year in excel.
for example:
Enter year:2017
Enter month:Jan
Date
1/1/2017
1/2/2017
1/3/2017
1/4/2017
.
.
.
.
the cells should auto populate when the month and year is entered.
thanks for suggestions in advance.
Without context, it's not clear what you need. Do you want the user to enter the data in dialog boxes or enter the data into two cells? What format will the user be expected to enter the dates in? For example, should January be entered as "Jan", "January", "1" etc.? You probably just need to have 31 formulas set up that reference the input cells, but you need to specify exactly how that input is handled first.
EDIT:
That was meant to be a comment, not an answer, so here is my actual answer:
In cell A1, set up a data validation rule. The rule should be a list with the source given as "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec" or the longer form if you prefer. Now when you try to edit this cell you have the option of selecting from a drop-down list of months.
If you want to limit the year range as well, you can do something similar in cell B1. Just create comma-separated list of valid years in the source field.
Enter the numbers 1 to 31 in cells A3 to A33 then enter this formula in cell B3:
"=DATEVALUE(A3&"-"&$A$1&"-"&$B$1)"
Autofill/copy that down to B33. The DateValue function takes the calculated string (for example "13-Feb-2017") and converts it to a date which you can then format any way you want. Note that this will produce the error "#VALUE!" if either of the input cells are blank or if the choosen month doesn't have 31 days, but you can modify it to your own needs.
Assume this.
Cell b1 tooks input as month, create a name range rng
cell d1 tooks input as year, create a name range yearsamp
column I and J have this, with a formula in j3.
=IF(MOD(yearsamp,4)=0,29,28)
month days
1 31
2 29
3 31
4 30
5 31
6 30
7 31
8 31
9 30
10 31
11 30
12 31
name above cell range as monthdays
use this formula in A2 and fill
=IF(VLOOKUP(mnth,monthdays,mnth,FALSE)>=ROW(A2)-1,DATE(yearsamp,mnth,ROW(A1)),"N/A")
This is another option to achieve this
You can use this formula also.set up as said above.
on first field for 1st date enter this on A2
=DATE(d1,MATCH(b1,I1:I12,0),1)
On A3 write this forula and fill
=IF(ROW(a2)-1<VLOOKUP(mnth,mnthdays,2,FALSE),a2+1,"")
As you have 31 cells with formula it return errors when the month day count are less than 31 but this formula show those as blank without errors.

EXCEL Max value for multple time/date intervals

I have an excel file as per the image attached
The date range in column D spans several days ie. there is also data for 10/08/2016; 10/09/2016, ect...
I am trying to get the maximum value in columnC for each 15 minute interval in column D.
eg:
10/08/2016 00:00 - 00:15 -- 0
10/08/2016 00:16 - 00:30 -- 25
10/08/2016 00:31 - 00:45 -- 13
and so forth until the end of the file.
Any help is appreciated.
First you need to get the 15 minute intervals. To do this, I put the Date/Time Start values in column F starting in F2 (I assumed row 1 is a header row). In cell F2 is this formula: =FLOOR(MIN(D:D),15/1440) and in cell F3 and copied down is this formula: =IF(F2="","",IF(F2+TIME(0,15,0)>MAX(D:D),"",F2+TIME(0,15,0)))
Then I put Date/Time End values in column G starting in G2 (because row 1 is a header row). In cell G2 and copied down is this formula: =IF(F2="","",F2+TIME(0,15,0))
Now you can get your maximum per interval. To do this, I put Max Interval Value results in column H starting in H2 using this formula copied down: =IF(F2="","",MAX(INDEX(($D$2:$D$11001>=F2)*($D$2:$D$11001<G2)*$C$2:$C$11001,)))
Adjust columns to suit your needs, and adjust the ranges ($D$2:$D$11001 and $C$2:$C$11001) to suit your actual data.

I am trying to find a formula that will allow me to calculate MAX/MIN without calculating anything after the current row

I want to use the Max/Min function to calculate the minimum number up to the current row, but not count anything after that row. See example below:
A B C
1 10 =MIN(A1:A1) I Want B1 to only count MIN from A1 to A1 from here, then
2 14 =MIN(A1:A2) from here I want B2 to count MIN from A1 to A2,
3 9 =MIN(A1:A3) Then A1 to A3,
4 6 =MIN(A1:A4) etc,
5 14 =MIN(A1:A5) etc.
I could go back and update each row manually, but I have over 700 rows that I want all this to apply to. Is there anyone who can help me with a solution to this problem?
Use this formula in B1, and copy downwards:
=MIN($A$1:$A1)
This is called maintaining referential integrity while writing any excel formula. It should give the desired result on copy towards right or downwards.

excel formula to extract dates with highest trade count

I need excel formula to show the dates when the trade count was maximum. Below mentioned are the excel columns
trade count. date
10 9 jan
12 8 jan
12 7 jan
Result : 7 jan & 8 jan
so the result can be highlighted in two different rows. or whatever convenient format.
kindly advice how it can be done easily.
Let your column C provide you with all the dates on which the MAX happens. You can always hide column C later.
Let C1 be the maximum from column A:
=MAX(A:A)
Now in each row, column C can build up your final output string. Copy from C2 down:
=IF($C$1=A2,TEXT(B2, "dd mmm"),"")
This gives you a column of either blank values, or the dates you need (correctly formatted as text).
Use column D to build up your final output string, by looking down column C:
=IF(C2="",IF(D3="","",D3),IF(D3="", C2,D3&" & "&C2))
Your result string will be given by cell D2.

Resources