Excel: Lookup Multiple values with duplicates in multiple columns - excel

I'm trying to link multiple lists and show all the values. Including duplicates.
My worksheet has data in 11 Columns. One column with Products(which can appear multiple times) and the rest with Store(which sell the products, no store sells the same product).
A small example here:
I've made a helper column(A) using the following formula : =B2&COUNTIF($B$2:B2,B2) . The helper column counts how many time a product show up in the Products Column(B). I thought it was needed.
I've managed to sort the data a bit using =VLOOKUP($C$2&ROWS($L$1:L1),$A$2:$C$11,2,0) like this :
Result
But I want to sort the data in a single Column for each store like this:
Desired Result
, without having to change the formula every 2-3 rows, as some store have 30 or so products. Is this something achievable with either formulas or VBA?
I would like to have the results in one column :
List Store 1 items as many times as they appear in Product column.
If an item(from Store 1) doesn't show up in Product column show "Product name -"
Product Column can have repeatable items
Each store has different products, so there's no conflict there.
If possible, since i have they Helper Column, if a product shows up 4 times, when i drag the formula in the 5th row it should jump to the next product.
Hope this is clear enough. Thank you
Later Edit: Maybe this helps a bit in understanding what I want to obtain.
Column 1 helper I've added it to count how many times a product shows up in Column 2. I want to get a separate column, which shows the items in Column 3(store1) x how many times they appear in Products Column. In the example above Store1 has product "Hansa" which appears 4 times in Product Column so it should appear 4 times in the separate column, after it there's product "Korek" which appears 1 time in Product Column so it should appear one time in the separate column under "Hansa" and so on. So basically I want to compare the third column to the second and show to values in the third x times they appear in the second in a different column.

This formula uses F1 as a helper cell, which is needed to count the matches in the product list.
Enter this FormulaArray in F1:
=SUM( IF( ISERROR( MATCH( $B$2:$B$11, $C$2:$C$6, 0 ) ), 0, 1 ) )
Enter this formula in E2:E11:
= IFERROR( INDEX( $C$2:$C$6,
AGGREGATE( 15, 6,
MATCH( $B$2:$B$11, $C$2:$C$6, 0 ),
ROWS( E$2:E2 ) ) ),
IFERROR( INDEX( $C$2:$C$6,
AGGREGATE( 15, 6,
ROW(E:E) / ISERROR( MATCH( $C$2:$C$6, $B$2:$B$11, 0 ) ),
ROWS( E$2:E2 ) - $F$1 ) ) & "-", "" ) )
Note that the helper column A is not needed.

Related

Generating a random comma separated list of product ID's then summing their value?

In column A I have a product ID, in column B the product price.
I want to take a random number of product ID's (lets say between 1 and 5), add them to a cell in a comma separated format, then in another cell sum the product prices of those products.
Any help would be greatly appreciated.
Thanks
If you had Prod ID in column A and price in column B, you could make a random generator of X products (Let's say in E2) like this:
=TEXTJOIN( ", ", 1, INDEX( A2:A11, RANDARRAY(5,1,1,10,1) ) )
where 5 is the number of elements you want and 10 is the count of all products and A2:A11 is the list of product IDs.
Then in let's say E4, you could calculate the sum of the randomly chosen prices with :
=SUM( XLOOKUP( FILTERXML( "<m><s>" & SUBSTITUTE( E2, ", ", "</s><s>" ) & "</s></m>", "//s" ), $A$2:$A$11,$B$2:$B$11,,0) )
where A2:A11 are the prod id's and B2:B11 are the prices.

PowerPivot Group By to find a count of values

I have a PowerPivot data model with thousands of rows and I'm trying to add a column that shows me the number of times a value occurs based on grouping the values in other columns. For example, I want to count the total number of times an item has shown $ greater than zero for a dept by for each combination of item and date. in the picture example provided here, 9 total stores show $ for the item for the specific date. I'm looking to do this in a column instead of a measure so I can merge it with other data. I have it solved as a measure with this formula:
CALCULATE (
SUMX (
ADDCOLUMNS (
SUMMARIZE (
Append1,
Append1[UPC],
Append1[Weeks]
),
"NumStoresSell", CALCULATE(
COUNT ( Append1[$] ),
Append1[$] <> 0
)
),
[NumStoresSell]
)
)
Any ideas on how I can solve it as a column?
thank you!
This DAX formula will return the number of rows in a table that matches all three criteria specified, row-by-row. The && means AND. You can swap this out with || for an OR criteria.
This example is a formula entered into a table named Summary and counts the rows in a table named Data with the columns for Item, Transaction Date and Transaction Amount having values matching the formula's row in the Summary Table.
= CALCULATE(
COUNTROWS(Data),
FILTER(Data,Data[Item]=Summary[Item],
&&Data[Transaction Date]=Summary[Transaction Date]
&&Data[Transaction Amount]=Summary[Transaction Amount]
)
)

Using Correl Function in Excel for Varying Array Sizes

So the current setup of the problem at hand is that I have 4 columns, Employee ID, Category 1, Category 2, and Category 3. I need to find the correlation between Category 1 & Category 2, Category 1 & Category 3, and Category 2 & Category 3 for each Employee ID. The issue is that the array length for each Employee ID is different. Some employees will have 5 records, some employees will have 8 records to their ID.
This problem would be simple if the Subtotal button had the CORREL function built into it given its grouping by feature.
How would I go about calculating the 3 correlation coefficients for each unique Employee ID? Excel function or VBA works
You need to use an array formula. Please see this screen shot of a sample situation:
As you can see the formula for cell G2 is: =CORREL(IF($A$2:$A$16=F2,$B$2:$B$16,""), IF($A$2:$A$16=F2,$C$2:$C$16,"")) That is saying if cell in column A matches your employeeId, include the cell in corresponding column in the array (Column B for the first IF and Column C for the second ID). After entering in the formula you need to make sure you hit Ctrl+Shift+Enter to tell excel you want to do an array formula or Command+Enter on a Mac.
You obviously need to modify the formula to fit the size of your data and you can copy that formula to any cells if you setup your $s correctly.

Count If with multiple criteria and unique values

I have a sheet of data and want to run a count on the values in Raw data with the following criteria:
If the value in raw data is repeated FOR EXAMPLE London No1 and London No1 AUTO only to be counted once, but if the value in raw data is London No1, London No2 and London No1 Auto then only to count 2 (to count London No1 and London No2 only).
Raw data
London No1
London No2
London No1 Auto
London No2 Auto
Bristol No1 Auto
Cardiff No1
Cardiff No2
In this example Result should be: London - 2, Bristol - 1, Cardiff - 2.
This solution uses only one "working column" and assumes the following:
The list of Raw Data is located at A1:A16 (adjust as required)
The Raw Data records follow this syntax City NoX string all separated by a blank space. X is one digit number (do let me know if there will be larger numbers in order to adjust the formula)
(All ranges include header)
With the list of results located in the same worksheet at B1:D16
(adjust as required) and including the following fields:
Site: List of Cities to count in Raw Data
Unique Record: Used to list unique "clean" city records before counting. Enter this FormulaArray in D2 and copy till last record
(Formulas Array are entered by pressing [Ctrl] + [Shift] + [Enter]
simultaneously)
=IFERROR( INDEX(
MID( $A$2:$A$16, 1, 2 + FIND( "No", $A$2:$A$16 )),
MATCH( 0, COUNTIF( D$1:D1,
MID( $A$2:$A$16, 1, 2 + FIND( "No", $A$2:$A$16 ))), 0 ) * 1 ), "" )
Result Count: Enter this FormulaArray in C1 and copy till last record
=IF( EXACT( $B2, "" ), "",
IFERROR( COUNTIF( $D$2:$D$16, $B2&"*" ), "" ))
Assumptions
So if I understand your clarifications, you have a list of cities, and each city might have a different "No" on it. ie: some will be "No1", "No2", etc. Also, some might have "Auto" on it. There are sometimes duplicates, ie: "London No1" might appear twice. Also, whether or not the word "Auto" appears, it will be a duplicate if that "No" already appears. ie: "London No1" is identical to "London No1 Auto".
Helper Columns
To count how many unique instances of each city there are, I propose you use a helper column which first removes the word auto, and then only displays itself if it is not a duplicate of a prior entry.
With your data in column A, starting at A2, enter this formula in B2 and copy down:
=IF(ISERROR(MATCH(TRIM(SUBSTITUTE(A2,"Auto","")),$B$1:$B1,0)),TRIM(SUBSTITUTE(A2,"Auto","")),"")
This formula works as follows:
-First it takes the text in A2, and it replaces the word "Auto" with "". Then it TRIMS the resulting text, which means it earases any trailing spaces at the end. It takes that trimmed text, and attempts to MATCH it with the previous rows in column B. If it doesn't find a match, it results in an error. IF it ISERROR, then it shows the text (because it's the first time it has appeared). Otherwise, it shows "".
Array Formula
Now that you have this in column B, we will use Array Formulas to count how many unique instances of each city appeared. An Array Formula is a specific formula which calculates many time over an entire range, instead of just one cell. It then returns an Array of results, which we need to collapse into a single answer. For example:
=SUM(IF(A1:A5>5,B1:B5,""))
[Confirmed with CTRL + SHIFT + ENTER instead of just ENTER]
In the above example, the Array Formula will check if each individual cell from A1:A5 is a number larger than 5. If it is, it will return the cell from column B in that row. It then takes all resulting answers from column B (where A was > 5), and SUMS them to a single number.
In this case, the Array Formula will be as follows [Starting in D5 in your image and moved one column to the right, immediately to the right of the first city name, and copied down for each city; I am assuming that your raw data goes from A2:A100]:
=SUM(--NOT(ISERROR(SEARCH(C5,$B$2:$B$100))))
Confirm this formula with CTRL + SHIFT + ENTER instead of just ENTER. Then copy down for each city name in column C.
It works by attempting to search each unique value in column B for the city name shown in that row of column C. Wherever it the city name is not present, ISERROR returns TRUE for that element of column B. Then NOT turns all TRUEs to FALSEs and vice versa. Then the -- tells excel to convert TRUE and FALSE to their numerical equivalents [1 and 0, respectively]. So we will have a TRUE [AKA 1] for each match, and FALSE [AKA 0] for everything else. The sum of all 1's is the number of matches of that city name in your list of unique entries.

Finding companies appearing with different IDs in MS Excel

I have 2 columns in my data:
A - each company's unique ID.
B - the company name that corresponds to the respective ID.
This type of data extends to 13,000 rows. For instance:
Col A Col B
12 Google Inc
12 The Google
14 Google
18 Amazon
18 Amazon
21 Amazon INC
18 Amazon
...
As you can see from the example above, the issue is that sometimes the company has a different ID appearing. Furthermore, although in all 3 cases, the company is still the same, the fact that they've been worded differently makes it hard to do an exact match.
My goal in this exercise is two-fold:
Find which companies have different IDs showing.
Identify the row at which this happens.
It would be cumbersome to go through all 13,000 rows. What Excel formulas would do the trick?
You could use pivot tables to count how many duplicates each name has.
I would also:
Order the list by column B.
Add a formula in column c that compares the formula row with the previous row.
For example consider a formula in row 5:
=IF(B4=B5,"Identical","Different")
You could build in more intelligence for example compare the first word in the name in row 5 to see if it is in the row 4 name. eg
=IF( iserror( find( LEFT(B5,FIND(" ",B5,1)-1) ,B4,1) )
,""
,"Similar")
You could combine the above tow into a single function, or may use both in different columns (which is easier)
PART 2:
The data must be ordered by column B!
So using the above logic to compare the IDs you should add another column (column F) with this formula
= find( LEFT(B5,FIND(" ",B5,1)-1) ,B4,1)
Then add another column (column G)
=IF(B4=B5
, B5
, IF( iserror(F5) )
,""
, F5 )
)
This results in a value in column G which is either the identical company name or the first word of a company that has a matching name.
You can then add another column (column H) which compares the id's of rows with the same IDs
=IF(F4=F5
, IF(A4<>A5, "Different IDS, "Ok IDs")
, "First row in company group"
)

Resources