To sum data for until a certain date - excel

01-Mar 02-Mar 03-Mar
Actual 1 1 1
Allocation 3 0 2
Variance 2 -1 1
Assume the date today is 3rd March
How to sum the value of Actual until 2nd March only

use SUMIF:
=SUMIF($E$1:$G$1,"<2014-03-03",E2:G2) //range, criteria, sum range
if you want to sum values less than today, you can modify the formula as:
=SUMIF($E$1:$G$1,"<"&today()-1,E2:G2) //this will evaluate the criteria as dates till yesterday
Here's the sample output.
Update
If you're using a date value from cell to compare as criteria, make sure that it's a Date value otherwise it not give you desired output. See here in the formula bar:
The value in cell is "3-Mar" but is a date value as it shows in formula bar.
In case if it's a text value and you want to compare as date, use TEXT function to convert and then compare:
You can see here in below picture where I've a string value in cell K1 and in the next picture how i used TEXT function to convert and use it as a Date value:
Picture1
Picture2
HTH !

Related

Return cell's value based on its date range in Excel

I have a table with specific products and dates and I want to get the cost values that correspond to that date . The source table has a range of dates and not an actual match (that is my problem).
Here is the task: we are trying to fill column "Cost" based on Sheet 2
SHEET 1:
Product
Date
Cost
price
First
29/12/2021
result 1 (formula type X)
100
Second
05/01/2021
result 2 (formula type X)
200
The other Sheet has the date ranges with the desired results (selling prices), like this:
SHEET 2:
Product
Start Date
End Date
Cost
First
28/12/2020
03/01/2021
result 1
Second
04/01/2021
11/01/2021
result 2
PS. I have different costs for different products in the same date. So, we needed to also add a parameter that will match the Product from one sheet with the product of the other.
If the given Ranges both start at A1 and end at D3 then the following works in Sheet1!C2:
=INDEX(Sheet2!D:D,MATCH(1,(B2>Sheet2!B:B)*(B2<Sheet2!C:C)*(A2=Sheet2!A:A),0))
This is an array formula to be entered with ctrl + shift + enter
It Indexes sheet2 column D and searches for the first match where all mentioned condition are true (=1). Each condition produces 1 or 0 for each cell in the range and multiplies it by the result of the cell from the next range in the same row. If either of the conditions is false it multiplies by 0 resulting in 0.
If all conditions are true it will result in 1 (111).
The overall produces an array of {0,0,1,0,...} and the match function returns the N'th occurance of the first 1, which is equal to the row number of the conditions being true.
Since you mentioned tables I'm going to assume you mean a real Excel Table and not just cells formatted into a table like appearance.
Sheet 1 Table is named: tbl_ProductPrice
Sheet 2 Table is named: tbl_ProductCost
"Cost" column formula in sheet 1:
=SUMIFS(tbl_ProductCost[Cost],[Date],">="&tbl_ProductCost[Start Date],[Date],"<="&tbl_ProductCost[End Date])
Explanation
First SUMIFS parameter, "Cost" column, is what will be summed up if all criteria are true.
First IF:
Second parameter is the date criteria to check.
Third parameter is what to check against, is greater than or equal to start date.
Second IF:
Fourth parameter is the date again for the second if statement
Fifth parameter is checking if less than or equal to the end date.
Results:
EDIT
Based on your comment regarding multiple product entries for different date ranges I would go with the Index Match approach instead.
=INDEX(tbl_ProductCost[Cost],MATCH(1,([#Product]=tbl_ProductCost[Product])*([#Date]>=tbl_ProductCost[Start Date])*([#Date]<=tbl_ProductCost[End Date]),0))
Enter formula with Ctrl+Shift+Entersince it's an array formula.
I added in a product match as well since you indicated multiple date ranges for each product type.
Results

How to assemble Offset function with Condition?

I Have date data in Column A and values data in Column B.
My aim goal is that for each date in column A :
look if one value (column B) during 1 year is less than 90% of the corresponding Value of the date.
This is my data:
Output example :
I start at the first date (31/12/1986) and see the 900.82 value.
I calcul 900.82 * 0.9 = 810.73
So i look if value in line 3 is inferior to 810.73,
If not
I look if value in line 4 is inferior to 810.73,
line 5, 6, 7 ,8..... during 1 year (that mean I stop this the 31/12/1987).
If it is
I stop and i look the next date (01/01/1987) and do the same.
I am agree to translate it in VBA code, but it could be better on Excel.
I first tried an algo to understand the problem :
-Look the first date in column A
-Look the corresponding value in Column B and save it as Value
-Offset to the next date in column A
-Look the corresponding value in Column B and save it as Range.to.compare
-If Range.to.compare < Value * 90% then write "ok" in Column C
-Else, Offset to the next date in column A...
-Untill 1 Year (Untill Year(Date in Column A)<Year(Date in Column A) +1
I try to translate it in Excel or VBA.
This this what I tried by Excel :
But it works only for 1 day instead of 1 year
I think this is what you're after. I broke the calculation into multiple columns to show the steps.
First I calculate the 90% value, in column C.
Column D is where most of the magic happens. In column D I find all rows that have a date < the current date + 1 year, and get the value (Col B) for each of those rows. I then take the minimum of all those values. Note this is an array formula so you need to press shift-ctrl-enter after you type it in.
Now that I have the minimum from the each range, I just need to compare that with the 90% value.

Counting lowest values from multiple columns

I have a table and I need to count expiration for a year but I have two columns and I need to count the lowest value from them. What function would help with this. Here is a small Example
Name Expiration date Break date
Nr.1 31-Aug-2019 28-Feb-2023
Nr 2 18-Oct-2018
Nr 3 30-Sep-2018 21-Jun-2017
Nr. 4 1-Jan-2018
AS you can see there will be here:
2017 2018 2019 2020
1 2 1 0
You could use an extra "helper" column which takes the minimum between the expiration date and break date. (Accounting for the possibility of the Break date being empty)
Then your equation to find the totals for each year would just be a simple COUNTIF on that new column.
Slightly shorter version of a formula for the helper column:
=YEAR(IF(COUNT(B2:C2)=2,MIN(B2:C2),B2+C2))
with the difference that this will return a year (other than 1900) if there is a blank in the Expiration date column that is next to a populated cell in the Break date column.
For the actual counts I would choose a technique that has been deemed off topic for SO.
Solution with no helper column
Formula:
=SUMPRODUCT(--((($B:$B<$C:$C)+($C:$C=""))*($B:$B<>"")*(YEAR($B:$B)=E$1))+((($C:$C<$B:$B)+($B:$B=""))*($C:$C<>"")*(YEAR($C:$C)=E$1)))
Assumptions:
Data in columns A:C, with Expiration Date in B and Break Date in C
Year (2017,2018,2019,2010) in E1:H1
The formula can be dragged horizontally from E2 to H2.
Formula Logic (pseudo-code):
IF(OR(AND(OR(B<C,C=""),B<>"",YEAR(B)=X),AND(OR(C<B,B=""),C<>"",YEAR(C)=X))) THEN TRUE
Alternate Solution Using Table
Because the headers break the original formula, you'll need to make the column references more specific to where the data actually is. A table is the easiest way to do that.
=SUMPRODUCT(--(((Table1[Expiration Date]<Table1[Break Date])+(Table1[Break Date]=""))*(Table1[Expiration Date]<>"")*(YEAR(Table1[Expiration Date])=$E1))+(((Table1[Break Date]<Table1[Expiration Date])+(Table1[Expiration Date]=""))*(Table1[Break Date]<>"")*(YEAR(Table1[Break Date])=$E1)))
Tables don't play nice with formulas dragged horizontally, so I put the years in a column:
=SUM(IF(YEAR(IF($B$2:$B$5
Note: This is an array formula, you must paste it in the cell, then hit ctrl+shift+enter and then you can copy and paste it across your table.
The cell works if your data is in A1:C5 and you have the years you want to test across E1:H10. You could then paste the above formula in E2, and then paste accross your table.
The array formula does the following:
The first IF statement checks to see which value is lower, ColB or ColC.
The embedded IF statements then check to make sure the values are not 0. If they are 0 they return the other column, if they are not 0, they return its own non-0 value.
The YEAR function extracts the year from each date.
The last IF function preformed (but the first written in the function) tests the year against the cell above the sum. If the year matches, it returns 1, if false, 0
The SUM statement simply sums all the true values

Formula for returning a specific date based on input

I have a bit of a puzzle regarding formulas for returning a specific date. At present I have a formula that calculates a date exactly 6 months after the date entered So in column D a date is entered and in column F this formula is set =IF(D196,EDATE(D196,6),"")
This gives me a date exactly 6 months later. What I want to do is have the formula produce the date exactly 6 months minus 1 day. I can get the minus 1 day with the formula =IF(D196,(D196-1),""). I just haven't worked out if it is possible to combine the two together somehow. Or am I barking up the wrong tree and need to have a completely different formula?
Just throw a -1 at the end of if true formula
=IF(D196,EDATE(D196,6)-1,"")
If just
=EDATE(D196,6)-1
is used then if there is no value in D196 excel defaults to 1/1/1900

Using Max function result in SumIFS Excel

I have a table like the image given above. There is another sheet which reports some information based on this data. I need the sum of Apples in the last week for a given month.
The answer for apples for 8 th month would be 14 assuming there is another record as Apples - 32 - 10 - 8.
So I would have to find max week number for a given month and then sum the quantity for Apples with max week number
The formula written is
=SUMIFS( C2:C300, A2:A300, H16, B2:B300, MAX(IF(D2:D300=MONTH(TODAY()-1),B2:B300)))
H16 contains the word "Apples"
Column A - Item
Column B - Week
Column C - Quantity
Column D - Month
Column H - Unique Items again..
MAX(IF(D2:D300=MONTH(TODAY()-1),B2:B300)) returns the correct max as 32 for month 8 but the formula returns the value as 0. If I put the max formula in aseperate cell and refer that cell in main formula, it works as expected. I am not sure why the result of max value is not being used for sumif function.
Your formula is good. all you need to do is to convert it into Array Formula. Just type the formula with Ctr + shift + enter.
{=SUMIFS( C2:C300, A2:A300, H16, B2:B300, MAX(IF(D2:D300=MONTH(TODAY()-1),B2:B300)))}
Actually, without array, the part IF(D2:D300 evaluates to #value error as Excel doesn't not know how to compare an array against one value.
Hint: Not sureif you know it already, but anyways, always use Formulas --> Evaluate Formula to pin-point an error in a formula.

Resources