I have monthly data in rows in column A. I also have monthly data in headers from column B to Column G. In Column H i have current month populated for all rows. I would like to display the value where, for example if the month in row is Jan and current month is Mar, then find the value where Jan and Mar intersect and do this for all rows. I tried using the following formula in Column J but it only gives the first value when it works. The result in Column I is desired. Attached is the picture for clarity.
=INDEX(B1:H2,MATCH(A2,$A$1:A2,0),MATCH(A2,$B$1:H2,0))
You can do it with SUMPRODUCT.
I made a fake dataset with different values than the ones you show, so i could test properly if changing Current month would work.
It works even if column CurrentMonth holds different months
My formula is:
=SUMPRODUCT(--($B$1:$G$1=H2);B2:G2)
This is how it works:
--($B$1:$G$1=H2) will return an array of 1 and 0 if range B1:G1 is equal to current month in that row. So in case CurrentMonth=Mar then it will return {0;0;1;0;0;0}
With SUMPRODUCT we multiply previous array by range B:G in current row, so for row 2, it would be B2:G2. So as example, it would be {0;0;1;0;0;0} * {1;2;3;4;5;6} = {0;0;3;0;0;0} and we sum up this array, getting 3
just use INDEX with one MATCH:
=INDEX(B2:G2,,MATCH(H2,$B$1:$G$1,0))
Related
If I have table 1 with OrderIDs and CallIDs and table 2 with CallIDs (that are referenced in table 1) and callDates, how can I find the number of orders within a given date range?
I believe what I need to do is get the calls that are within a date range in table 2, then check if the CallIDs exist in table 1, then get the count of the result. I just do not know how to put it all together in a formula. For instance in the picture, the number of orders in February should be 3.
=SUM(COUNTIFS(E2:E15,">="&DATE(2022,2,1),E2:E15,"<"&DATE(2022,3,1),D2:D15,B2:B8))
COUNTIFS creates an array of 0's and 1's (respectively FALSE and TRUE) for the date range in column E containing values greater than or equal to February 1st and smaller than March 1st and where the call number from column D is found in column B.
SUM adds up the 1's and 0's resulting in your count of matches in that range.
I have simple problem, but I've not be able to get an answer from searching. I require a column to calculate the number of the nth occurrence of a value. It's best explained in this picture
I require a method to calculate column B.
I'd be very grateful for any help.
Are you looking to merely provide a count of the distinct entries of column A in column B? Or merely add a formula to come up with the table in your link?
If the latter, then the formula to write in cell B2 is:
=COUNTIF(A$2:A2,A2)
then copy/paste it down column B. Note - if your data is both a Date and Time, but the cell is formatted to only display a date, you may not get the results you want. You'd need to interject a new column with a "floor" calculation to round the date/time value to a date (Excel date times are decimal, with integer part dictating the date, and remaining 0.0 -> 1.0 dictating the time of day)
If you just want to derive a table of the counts of distinct entries in column A, then a pivot table will do this for you - simple add a pivot table to cover the data in column A, then select column A into the rows category, and then also drag it into the values category, ensuring the field is set to "Count of". You should then have a table with the distinct entries in your data set in one column, and the count of their occurrences in the other column.
You can use the COUNTIF worksheet function, with a relative address.
Eg. In cell B2, enter this formula:
=COUNTIF(A$2:A2,A2)
And then fill-down.
Use the following formula to generate the required series:
=COUNTIF($A$1:A1,A1) and strech(copy) it in all the cells
This will generate result like this:
A 1 COUNTIF($A$1:A1,A1)
A 2 COUNTIF($A$1:A2,A2)
C 1 COUNTIF($A$1:A3,A3)
C 2 COUNTIF($A$1:A4,A4)
B 1 COUNTIF($A$1:A5,A5)
B 2 COUNTIF($A$1:A6,A6)
A 3 COUNTIF($A$1:A7,A7)
C 3 COUNTIF($A$1:A8,A8)
D 1 COUNTIF($A$1:A9,A9)
D 2 COUNTIF($A$1:A10,A10)
D 3 COUNTIF($A$1:A11,A11)
D 4 COUNTIF($A$1:A12,A12)
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
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.
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