What lookup is appropriate for a matrix of data - excel

I have a 'points matrix' the idea is, a sales person sells an item to a business, dependant on what product and the date it was booked (creation date) an amount of points is allocated.
'Product 1 +', 'Product 2 +', 'Product 3+' are the same products as product 1, 2 and 3. However they become + when they meet the criteria of being new (Column 'New' = YES).
What is the best way to pull through the correct points when following the above criteria? Happy to use VBA or formulas but would prefer both.

By assuming you first row in points in number 14
Try this formula in cell "F14": =IF(E14="YES",VLOOKUP(D14,$A$2:$G$11,MATCH(CONCATENATE(C14," +"),$B$1:$G$1,0)+1,FALSE),VLOOKUP(D14,$A$2:$G$11,MATCH(C14,$B$1:$G$1,0),FALSE))

You could also do this, I prefer using INDEX MATCH, since it is more flexible. The concept is the same.
=IF(E14="YES",INDEX($A$1:$G$11,MATCH($D14,$A$1:$A$11,0),MATCH($C14&" +",$A$1:$G$1,0)),INDEX($A$1:$G$11,MATCH($D14,$A$1:$A$11,0),MATCH($C14,$A$1:$G$1,0)))

Related

Find the highest value and return adjacent cell until value changes in another cell

I am an excel novice, so I hope I am explaining my problem well enough:
exceltable
Field A is the District the candidate is running in, Field B is the candidate name, Field C is the percent of the vote the candidate received, and I need Field D to calculate the District winner's name.
I am trying to calculate the name of the District winner into Field D until the District changes. I know there is probably a much better way to do what I am trying to do, but here is the formula I have pieced together so far: =IF(A2="",A1,A2 (INDEX(B2:B3,0,MATCH(MAX(C2:C3),C2:C3,0))))
Any help is appreciated!
You may try-
=CHOOSE({1,2},UNIQUE(A2:A19),BYROW(UNIQUE(A2:A19),LAMBDA(x,INDEX(SORT(FILTER(B2:C19,A2:A19=x),2,-1),1,1))))
With header-
=LET(a,UNIQUE(A2:A19),b,BYROW(a,LAMBDA(x,INDEX(SORT(FILTER(B2:C19,A2:A19=x),2,-1),1,1))),VSTACK({"Dist","Candidate"},HSTACK(a,b)))
You can try this in cell E2:
=LET(rng, A2:C19, dists, INDEX(rng,,1), names, INDEX(rng,,2),
pcts, INDEX(rng,,3),
distsUx, UNIQUE(dists),
result, MAP(distsUx, LAMBDA(dist,
TEXTJOIN(",",,FILTER(names, (dists=dist)
* (pcts = MAX(FILTER(pcts, dists=dist)))))
)),
HSTACK(distsUx, result)
)
Here is the output:
Note: In case there is more than one name within the same district with the same max pct, it returns the names delimited by comma.

How to get min() max() sequentially from a single column?

Hi Stackoverflow Community,
This is my first post, apologies ahead if I haven't structured my question better, I'll try to improve on it later on.
I have a 2 excel columns with street address numbers and street address, none of which are unique hence using vlookup/index match is tricky.
I am trying to populate another column with the minimum and maximum value of the street address numbers using TEXTJOIN and it works, however I need the min/max for each specific street address group, there are close to 1 million lines of data.
For example, min=1, max=13, on florence st, min=3, max=53, on gibson st
Is such a formula helpful for you:
=MINIFS(B$2:B$10,A$2:A$10,"Ramsay street")
As you see, I take the minimum value of the "B" column, based on a criterion on the "A" column.
Hereby a screenshot of an example:
If you are on Excel 365 - current channel you can use this formula:
=LET(streetnamesUnique,UNIQUE(data[StreetName]),
minNumber,BYROW(streetnamesUnique,LAMBDA(s, MINIFS(data[Number],data[StreetName],s))),
maxNumber,BYROW(streetnamesUnique,LAMBDA(s, MAXIFS(data[Number],data[StreetName],s))),
HSTACK(streetnamesUnique,minNumber,maxNumber))
If on Excel 365 semi annual channel:
=LET(streetnamesUnique,UNIQUE(data[StreetName]),
minNumber,BYROW(streetnamesUnique,LAMBDA(s, MINIFS(data[Number],data[StreetName],s))),
maxNumber,BYROW(streetnamesUnique,LAMBDA(s, MAXIFS(data[Number],data[StreetName],s))),
MAKEARRAY(ROWS(streetnamesUnique),3,LAMBDA(r,c,
IF(c=1,INDEX(streetnamesUnique,r),
IF(c=2,INDEX(minNumber,r),
INDEX(maxNumber,r))))))
Both formulas first retrieve the unique streetnames - then retrieves, per each streetname min and max number.
In the end the new range is built from these values - either by HSTACK or MAKEARRAY.

Create a text cell value based on row entries and corresponding columns

I understand this is a tough way of wording the problem I have. Please try and help me.
I want to create a Column called Orders which contains cells based on corresponding item values.
So if I have columns: FlatNo, Truffle, Pineapple, Mango, Chocochips; I want to create a column called Orders which has value:
FlatNo - A51
Mango - 1
Chocochips - 1
(if no values in the Pineapple & Truffle Columns, none show up in Orders columns)
See image
How do I do that ? Thank you in advance
You can use IF and &. & simply puts the different desired things altogether.
Hope the following formula will get you the result for column orders. I have put the number of each item ordered inside parentheses before the item.
="Flat No. "&A2&IF(ISBLANK(B2),"","-("&B2&")"&$B$1)&IF(ISBLANK(C2),"","-("&C2&")"&$C$1)&IF(ISBLANK(D2),"","-("&D2&")"&$D$1)&IF(ISBLANK(E2),"","-("&E2&")"&$E$1)
For instance the third order is shown like this: Flat No. E-23-(1)Truffle -1 Pc Rs 60-(3)Mango -1 Pc Rs 60

Excel CUBEVALUE & CUBESET count records greater than a number

I am writing a series of queries to my workbook's data model to retrieve the number of documents by Category_Name which are greater than a certain numbers of days old (e.g. >=650).
Currently this formula (entered in celll C3) returns the correct number for a single Days Old value (=3).
=CUBEVALUE("ThisWorkbookDataModel",
"[Measures].[Count of Docs]",
"[EDD_Report].[Category_Name].&["&$B2&"]",
"[EDD_Report_10-01-18].[Days Old].[34]")
How do I return the number of documents for Days Old values >=650?
The worksheet looks like:
A B C
1 Date PL Count of Docs
2 10/1/2018 ALD 3
3 ...
UPDATE: As suggested in #ama 's answer below, the expression in step B did not work.
However, I created a subset of the Days Old values using
=CUBESET("ThisWorkbookDataModel",
"{[EDD_Report_10-01-18].[Days Old].[all].[650]:[EDD_Report_10-01-18].[Days Old].[All].[3647]}")
The cell containing this cubeset is referenced as the third Member_expression of the original CUBEVALUE formula. The limitation is now that the values for the beginning and end must be members of the Days Old set.
This is limiting, in that, I was hoping for a more general test for >=650 and there is no way to guarantee that specific values of Days Old will be in the query.
First time I hear about CUBE, so you got me curious and I did some digging. Definitely not an expert, but here is what I found:
MDX language should allow you to provide value ranges in the form of {[Table].[Field].[All].[LowerBound]:[Table].[Field].[All].[UpperBound]}.
A. Get the total number of entries:
D3 =CUBEVALUE("ThisWorkbookDataModel",
"[Measures].[Count of Docs]",
"[EDD_Report].[Category_Name].&["&$B2&"]"),
"{[EDD_Report_10-01-18].[Days Old].[All]")
B. Get the number of entries less than 650:
E3 =CUBEVALUE("ThisWorkbookDataModel",
"[Measures].[Count of Docs]",
"[EDD_Report].[Category_Name].&["&$B2&"]"),
"{[EDD_Report_10-01-18].[Days Old].[All].[0]:[EDD_Report_10-01-18].[Days Old].[All].[649]}")
Note I found something about using .[All].[650].lag(1)} but I think for it to work properly your data might need to be sorted?
C. Substract
C3 =D3-E3
Alternatively, go for the quick and dirty:
=CUBEVALUE("ThisWorkbookDataModel",
"[Measures].[Count of Docs]",
"[EDD_Report].[Category_Name].&["&$B2&"]"),
"{[EDD_Report_10-01-18].[Days Old].[All].[650]:[EDD_Report_10-01-18].[Days Old].[All].[99999]}")
Hope this helps and do let me know, I am still curious!

VBA: creating pivotTable from a collection or use a better algorithm?

I was wondering how, or if at all possible, to create a pivotTable using VBA given a collection. Or improve on the current algorithm for my code.
Currently, I have a collection with about 28000 items. Each item has an unique Id, item number, and price. I want to generate a new collection with the unique Id, part number that has the lowest price. So I was thinking generating the pivotTable will aggregate all the item numbers, and find minimum price. Then based on that table, I can generate a new collection, or should I improve on the algorithm I have?
For example:
item[unique_id]: item number, price
Item[1]: 11111, 10
Item[2]: 22222, 2
Item[3]: 11111, 3
Item[4]: 11111, 15
Item[5]: 22222, 1
Item[6]: 33333, 2
and then the result collection would be something like:
Item[3]: 11111, 3
Item[5]: 22222, 1
Item[6]: 33333, 2
Currently, I have code that does the following to create that new collection
For Each Item in OriginalCollection
' Temp item holder for comparison
Set minItem = item
i = 1
Do While (i <= OriginalCollection.Count)
if OriginalCollection(i).itemNumber = minItem.itemNumber And OriginalCollection(i).price < minItem.price Then
Set minItem = OriginalCollection(i)
' reduce the size of collection, so fewer iterations
OriginalCollection.Remove (i)
OriginalCollection.Remove (minItem.Id)
End if
i = i + 1
Loop
If Not InCollection (MinCollection, minItem.Id) Then
MinCollection.Add minItem, minItem.Id
End If
Next item
Thank you in advance.
Anytime I need to accomplish what you're seeking, I just sort the table by item number, then price. I'm assuming your data are in cells A1:C28000. In a neighboring column's cell, starting with D2, I enter the formula: =if(b2=b1,"",1). This tells me when there's a change in item number. And every time there's a change in item number, I know I've found the cheapest price for the new item (because each group of item numbers is sorted by ascending price). Copy that formula in column D down the length of your item list.
Turn on your auto-filter and filter for where values in column D=1. Those are all of your lowest prices for each item. (adjust for if your very first item doesn't have a duplicate; i.e., just add column headers)
This approach doesn't use pivot tables, but based on your problem description, I'm not sure you need them.

Resources