Excel: Match\Index specific column based on multiple criteria - excel

I have two Tables, Table 1 Column A is a rolling date column. Table 2 consists of four columns of differing "Trigger Dates". Table 2, Column 1 contains an Annual trigger, ie occurs once a year. Table 2 Column 2 contains Bi-Annual Triggers, and occurs twice yearly. Table 2 Column 3 contains Monthly Triggers, "12 dates" and Table 2 Column 4 contains Weekly Triggers, "52 dates".
Ok, so what I'm looking for is to a formula that will return the date trigger, where Table 1 Column 1 matches a condition (Annually, Bi-Annually, Monthly, Weekly) selected in a cell "we'll say F1, outside of any ranges that may be created.
Example: If Table 1 Col 2 = "01/02/2013" and I select "Weekly" in F1, the formula will look in the weekly Column in Table 2 to determine if "01/02/2013" exists.
I've allocated a named range to each column in Table 2
I've allocated a named range to the condition in F1 which is a drop down list
Any suggestions?

You might try:
=IFERROR(VLOOKUP(B2,INDIRECT(CHAR(72+MATCH(F$1,$I$1:$L$1,0))&":"&CHAR(72+MATCH(F$1,$I$1:$L$1,0))),1,0),"")

Ok, so supposing your Range Name is in F1, your formula to find the match would look as follows:
=If(IsError(Match(LookupVal,Indirect(F1),0)),"No Match", "Match")
...Something along those lines
Hope this helps point you in the right direction.

INDIRECT and VLOOKUP will be your friends here.
I constructed Table2 just as you had described, with the Annual,Bi-annual,Monthly,Weekly labels for the columns in the table - this will avoid having to keep named ranges up to date, as it's looking directly at the table in the formula
For the function, I then used VLOOKUP to find the date, in the column referenced by F1.
Column Reference: INDIRECT("Table2["&$F$1&"]")
Find Value: VLOOKUP([#Col2],INDIRECT("Table2["&$F$1&"]"),1,FALSE) (looking at column 1 in the return values, as I don't really care what value is returned.
This will return the date if found, and an error if not. I can then wrap the result in the IF(ISERROR( so I can return Yes or No if the date is found.
This produces the entire formula of
=IF(ISERROR(VLOOKUP([#Col2],INDIRECT("Table2["&$F$1&"]"),1,FALSE)),"No","Yes")
for the next column in Table1, so that when I change the value in F1, it will look for that column name in Table2, and let me know if it is found.

Related

Single formula with Multiple Countifs and where data table contains duplicate values in more than one column

The excel file contains a structure table. (which I find difficult to work with but I can't alter the file structure, I am just adding a summary tab with various counts from the data table.)
Item
Month
1
2
2
2
2
2
2
3
3
3
3
4
The item number itself can repeat and be repeated within the same month.
I was able to get a count of total number of unique items using this formula.
=SUMPRODUCT((Item_tab[Item]<>"")/COUNTIF(Item_tab[Item],Item_tab[Item]&""))
Looking for how to count the number of unique items within a specific month.?
Example of Desired output.
Edit/Set formula for Month 2 , output should be 2
Edit/Set formula for Month 3 , output should be 2
Edit/Set formula for Month 4 , output should be 1
I cannot figure out how to apply countifs to something that needs to avoid duplicates in multiple columns.
Tried this but returns #VALUE!
=SUMPRODUCT((Item_tab[Item]<>"")/COUNTIFS(Item_tab[Item],Item_tab[Item]&"",'Item'!M:M,6))
The month column was added later and I don't know how why or how to get that column to have the structured table column Header like everything else.
The sheet name is Item
The Table Name is Item_tab
I can find where to rename the table but not the columns. Not sure the variance is causing an issue. The month column is absolutely part of the table in every way that I can see.
You can try the following in cell D2:
=LET(A, A2:A7, B, B2:B7, uxB, UNIQUE(B), cnts, BYROW(uxB, LAMBDA(u,
ROWS(UNIQUE(FILTER(A, B=u))))), HSTACK(uxB, cnts))
Here is the output:
If you want to get the result repeated instead of consolidating the result by unique months, you can try the following:
=LET(A, A2:A7, B, B2:B7, uxB, UNIQUE(B), BYROW(B, LAMBDA(u,
ROWS(UNIQUE(FILTER(A, B=u))))))
If you don't have such function available, you can try the following formula in D2, it produces the same result as the first formula:
=CHOOSE({1,2}, UNIQUE(B2:B7),
MMULT(N(MMULT(TRANSPOSE(N(B2:B7=TRANSPOSE(UNIQUE(B2:B7)))),
N(A2:A7=TRANSPOSE(UNIQUE(A2:A7))))>0), SEQUENCE(ROWS(UNIQUE(A2:A7)),,1,0)))
or using LET for a better reading and maintenance:
=LET(A, A2:A7, B, B2:B7, CHOOSE({1,2}, UNIQUE(B),
MMULT(N(MMULT(TRANSPOSE(N(B=TRANSPOSE(UNIQUE(B)))),
N(A=TRANSPOSE(UNIQUE(A))))>0), SEQUENCE(ROWS(UNIQUE(A)),,1,0))))

Number occurrences in another cell (Excell) [duplicate]

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)

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

Calculate Occurrence Number - Excel

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)

Excel VBA Lookup Methods

I have an issue that I've been scratching my head at; I've looked into the Index:Match lookup method, and V/HLookup, but I'm not sure these will help just yet. Here's what's happening:
I have two worksheets in excel-2007. One has a Customer ID column (which does and will have duplicate ID's in the instance that the customer did "x activity" more than one time in a month) and then the date that this happened in another column. The second sheet is for giving an overview of a specific day, IE what happened on 7-1-13.
The issue is that my raw data sheet is sorted via the first of the month descending, so 7-1,7-2,etc, and when I run the Vlookup, if a Customer ID has a record on 7-2 and on 7-15, the VLookup will pull data only from the 7-2 (first) row. Has anyone experienced this and found a workaround?
My current workaround would be to make either a new table for each day's data, or instead of using my VLookup of =Vlookup(A2, 'Data Sheet' A:D, 4, 0) to give the columns row numbers, like =Vlookup(A2, 'Data Sheet' A$1:D$30, 4, 0). This is a daily report, and that would be intense. Please help if you can!
(Another side note, I have one main sheet for the view, one data sheet where it's all collected, and then 30 sheets, one for each day of the month, this case being July). For each sheet, I've named them the day of the month, so I'm reflecting the data as such:
Sheets("7-1-13") has data from the 1st on it. The Data Sheet in it's entireity has data from 7-1-13 to 7-31-13. I need to reference ID's on the 1st to the data for the 1st and the 1st only.
I want to use something like this, but I'm having a hard time with it
=Vlookup(A2, 'Data Sheet', A:D (ONLY IF THE CREATE DATE OF THIS ITEM IS 7-1), 4,0)`
but of course it's not that easy :p
This may not give you your results in a format you like and still requires a bit of manual work, but without going the route of macros, I think this will get you one step closer. I thought of using an array formula to get all the IDs by a specific date.
Example:
A B
ID Date
1 5 7/1/2013
2 2 7/2/2013
3 5 7/3/2013
In this situation, I assume you want 5 from the first row to appear on your 7/1 sheet, 2 to appear on your 7/2 sheet, and 5 from the third row to appear on your 7/3 sheet
on your 7/1 sheet. you'll need to select the number of blank rows that matches your raw data (using the example above, you would be selecting A1:A3 on your 7/1 sheet). Once you have your cells selected, then enter the following formula in the formula bar and press Ctrl+Shift+Enter. This is what makes the formula an array formula.
=((Raw_DataSheet!B1:B3=DATE(2013,7,1))*1)*Raw_DataSheet!A1:A3
What this formula does is looks at all the dates in B1:B3 and finds the ones that equal 7/1/2013. Since you're using an array formula, this gives you the array {TRUE,FALSE,FALSE}. Multiply this by 1, and you get the array {1,0,0}. You now have an array that has a 1 for each row of B1:B3 that was equal to 7/1/2013. This array {1,0,0} is then multiplied by your Customer IDs {5,2,5}
5 * 1 = 5
2 * 0 = 0
5 * 0 = 0
So now your entire formula is equal to the array {5,0,0}. Since you selected A1:A3 on your 7/1 sheet, the values that should appear should be
A
ID
1 5
2 0
3 0
From here, you can always filter out the 0's and you'd just have a list of all the IDs that had the date of 7/1 from your Raw Data Sheet. You would also then replicate this for each of your sheets and just change the date in the formula...Yes, I know, way more complicated than you probably wanted but it's what I came up with!

Resources