Index Match multiple criteria with a `smaller than` criteria without arrays - excel

I have a list of data that is separated by Date, Team and their Category Score. Category Score changes for each Team on a daily basis and based on their actual score of the day, I'll need to identify the Category Score that they fall into.
For example, if on the 1st Jan 2018, Team A's score is 225. Team A's score whole fall in between 200 and 250. The assigned Score Category will then be rounded up to the last category which will be 200
However, the next day, Team A's Score Category is changed. The 225 score nicely rests on a Score Category and thus the assigned category will be 225.
Hopefully that gives a clear picture.
To help with the matter, the data is always sorted by Date and Team with ascending Score Category
I'm looking for an excel formula that hopefully does not use the array function.
I've so far looked at the Index Match formulas but they were all exact match that does not allow me to approximate to a value.
For e.g.
Date Team Score Category
1/1/2018 A 100
1/1/2018 A 150
1/1/2018 A 200
1/1/2018 A 250
1/1/2018 A 300
1/1/2018 B 300
1/1/2018 B 400
1/1/2018 B 500
2/1/2018 A 150
2/1/2018 A 200
2/1/2018 A 225
2/1/2018 A 300
2/1/2018 A 350
2/1/2018 B 350
2/1/2018 B 450
2/1/2018 B 550
Date: 1/1/2018
Team: A
Actual Score: 225
Category Score (Output): 200
Date: 2/1/2018
Team: A
Actual Score: 225
Category Score (Output): 225

Try this array formula:
= INDEX($C$2:$C$17,MATCH(B21,IF(($A$2:$A$17=B19)*($B$2:$B$17=B20),$C$2:$C$17),1))
Note this is an array formula, must be entered with Ctrl+Shift+Enter on your keyboard rather than just Enter.
See below, working example with your data. I also copied this cell from B22 to B27.
A few notes:
This formula only works if your Score Categories for a particular Date and Team combination are in ascending order (because using a third argument of 1 in MATCH requires that the data be sorted), but from the way your question is worded, it doesn't sound like this will be an issue.
The formula would probably also break if your Score Categories and/or Actual Scores are negative, since the IF statement effectively "zero's-out" the data you're not interested in for this particular Date and Team combination. But if the Actual Score is negative then it probably would erroneously consider one of these 0's as a match. This is just a guess, I didn't test this though.
Another thing to consider is to add a Score Category of 0 to the top of each Date and Team combination. I say this because if for example the Actual Score is lower than the lowest Score Category (e.g. if the Actual Score is 50 but the lowest Score Category is 100), then a match won't be found, and I'm guessing the formula would return an error.

Related

Why I am getting StatisticsError: no unique mode; found 2 equally common values while creating a pivot table?

Suppose I have this (randomic) df_bnb:
neighbourhood room_type price minimum_nights
0 Allen Pvt room 38 5
1 Arder Entire home/apt 90 2
2 Arrochar Entire home/apt 90 2
3 Belmont Shared Room 15 1
4 City Island Entire home/apt 100 3
Every row represents an Airbnb's booking.
I hope to generate a pivot_table in which Index is the column neighbourhood and columns are others data frame columns ['room_type', 'price', 'minimun_nights'].
I want entries of the abovementioned columns as mean, expect for room_type where I wish to have the mode. Like the following dataframe's example:
room_type price minimum_nights
Allen room type mode for Allen price mean for Allen mean min nights for Allen
Arder room type mode for Arder price mean for Arder mean min nights for Arder
Arrochar room type mode for Arrochar price mean for Arrochar mean of min nights for Arrochar
Belmont room type mode for Belmont price mean for Belmont mean of min nights for Belmont
City Island room type mode for City Island price mean fot City Is. mean of min nights for City Island
This is the code I try so far:
bnb_pivot = pd.pivot_table(bnb,
index = ['neighborhood'],
values = ['room_type', 'price',
'minimum_nights','number_of_reviews'],
aggfunc = {'room_type': statistics.mode,
'price' : np.mean,
'minimum_nights': np.mean,
'number_of_reviews': np.mean})
This is the error that I am getting:
StatisticsError: no unique mode; found 2 equally common values
I try to search for other sources, but I don't how to treat statistic.mode() while creating a pivot_table.
Many thanks in advance for any helpful indication!

Add Partial Text Match as Criteria to a Count Unique Formula

I've been trying to add a partial text match as a criteria to the formula below, but with no success so far:
=SUM(--(FREQUENCY(IF(Sales[ClientID]=A21;IF(Sales[Operation]="Sale*";Sale[InvoiceNumber]));Sale[InvoiceNumber])>0))
The piece IF(Sales[Operation]="Sale*"; is the one that when added, always give me 0 as the result.
Here's some data:
Sales Table
Date ClientID Operation InvoiceNumber Total
01/01/2019 18090 Sale Adv 101010101 100
01/02/2019 20897 Sale Cash 105327892 100
01/03/2019 18090 Sample 41357398 100
01/01/2019 30456 Sale Check 43167429 100
10/04/2019 779584 Sale Cash 4326719 100
01/05/2019 30456 Refused 34162781 100
01/01/2019 90909 Sale Cash 3412679821 100
Results Table
ClientID Purchase Frequency
779584 ???
Here's the solution I borrowed from Scot Craner, in case someone else falls into the same question:
=SUM(--(FREQUENCY(IF(Sales[ClientID]=A21;IF(ISNUMBER(SEARCH("Sale";Sales[Operation]));Sale[InvoiceNumber]));Sale[InvoiceNumber])>0))
Thanks everyone!

Cuberankedmember getting wrong order

I'm trying to create a top3 ranking from a data table varying metrics but each time I get the wrong order from the cuberankedmember, usually misplacing ranks 2 and 3.
The data I'm mostly focused on is regarding sales revenue. Power pivot sums all sales by store, quite straight forward.
From this I use a cubeset formula that captures store name, filtered by a month and year, which the user types in as any day for the month, and set the measure which to sort by (NTS) (code 1).
The cuberankedmember selects the cubeset and defines the position (code 2).
Then the cubevalue selects as members the cuberankedmember, filters once again month and year, then pulls in the measure (code 3).
E4 is the date
Code1 (cell C21):
=CUBESET("ThisWorkbookDataModel";
"NONEMPTY([Store_Dict].[Nome_DSR].children,
([Calendar].[Year].[All].["&YEAR($E$4)&"],
[Calendar].[Month Number].[All].["&MONTH($E$4)&"]))";
"Ranking";
2;
"[Measures].[NTS]")`
`Code2` (cell `D22`):
`=CUBERANKEDMEMBER("ThisWorkbookDataModel";$C$21;1;"a")
`C21` is the `CUBESET` formula
Code3:
CUBEVALUE("ThisWorkbookDataModel";
$D22;
"[Calendar].[Month Number].["&MONTH($E$4)&"]";
"[Calendar].[Year].["&YEAR($E$4)&"]";
"[Measures].[NTS]")
Actual Result:
Ranking Store NTS
1 a 606
2 c 425
3 b 428
Expected result:
Ranking Store NTS
1 a 606
2 b 428
3 c 425

Excel lookup value for multiple criteria and multiple columns

I am helping a friend with some data analysis in Excel.
Here's how our data looks like:
Car producer | Classification | Prices from 9 different vendors in 9 columns
AUDI | C | 100 200 300 400 500 600 700 800 900
AUDI | C | 100 900 800 200 700 300 600 400 500
AUDI | B | .. ..
Now, for each classification and each producer, we produced a list that shows which of the 9 vendors has offers the most lowest prices (in terms of count, so for example there are 2 cars from AUDI in the C class, so vendor A would offer the lowest price for both).
What we need: A way to calculate the average price for this vendor. So, if we see that the vendor A has the lowest price for AUDI cars in the C class, then we want to know the average price for vendor A for these cars.
I'm quite stumped since I can't use the "standard" index-match-small approach since the prices are stored in 9 different columns.
I've suggested to use a long if-chain like this: =if(vendor=A,averageif(enter the criteria and select the column of vendor A for average values),if(vendor=B,average(enter the criteria and select the column of vendor B for average values),... etc.).
But this method is obviously limited and does not scale well to higher dimensions.
We also would like to avoid using any addons.
You're going to need to create a separate table that has all unique classifications in the rows and all dealers in the columns (same as yours, but with duplicate rows removed). Then, in each cell, take the average price for that classification*vendor combination. This can be done by using a combination of sumif/countif. For example, if your second table had a column for classifications in cells M2:M[end], calculating the average price for the Audi C class offered by vendor 1 could be:
=sumif(C$2:C$[end],"="&$M2,$B$2:$B$[end])/countif($B$2:$B$[end],"="&$M2)
This would look something like this:
Then you could simply find the cheapest vendor by matching the min price. For example, the cheapest vendor for the audi C class in my example image would be:
=index($N$1:$V$1,match(min($N2:$V2),$N2:$V2,0))
A lot this could be done using PivotTables. If it is a one off thing, I would go that route, if it needs to be automated, then try using a multicondtional VLOOKUP (needs to be entered as a Matrix Formula: CTRL+ALT+SHIFT). This is simply an example, not based on your data:
{=VLOOKUP(A11&B11,CHOOSE({1\2},A2:A7&B2:B7,C2:C7),2,0)}
A better explanation is given here at chandoos site:http://chandoo.org/wp/2014/10/28/multi-condition-vlookup/

Count and average data inside categories under two types of conditions

I'm working on Excel with a lot of data and I'm having difficulty with knowing how to sort through it to get some important numbers. I have minimal Excel experience.
Right now I'm struggling with knowing how to get the average in the difference between two columns. The trick is that I have to get the average in difference when column A is less that column B and then, the same when it's more. And all that within a category.
So for example let's say I have 3 categories: Football, Soccer, and Basketball (these are just made up ones).
So in column A, I have: Soccer, Football, Basketball. Then, in column B and C, I have the scores for John and Adam for the last 3 months, respectively. Lastly, in column D, I have the differences between their scores.
So, for example:
Category John Adam Differences
Soccer 5 3 2
Soccer 6 2 4
Soccer 3 5 2
Soccer 4 0 4
I want to create a table for within each category I have a table like below:
NÂș of cases Avg. Difference between John and Adam
When John's score is >
When John's score is <
When they are equal
Is there some type of formula where I can say something like this:
If the category is Soccer (the category being in column A), take the difference between John's score (column B) and Adam's score (column C) when John's score is larger than Adam's score, then calculate the average of those differences? Then, I would use the same formula but tweak it when John's score is smaller.
Additionally, would there be a formula where I can also, calculate within the category Soccer, how many times John's score is bigger than Adam's?
My data is much larger and I can't do this manually.
A B C D
1 Sport John Adam Differences
2 Soccer 5 3 2
3 Soccer 6 2 4
4 Soccer 3 5 -2
5 Soccer 4 0 4
6 Basketball 20 15 5
7 Basketball 7 13 -6
8 Basketball 26 10 16
9 Basketball 8 11 -3
Type in D1:
=B1-C1
Drag the formula in Column D to all rows which there are values in columns A, B and C.
Create the PivotTable.
Drag Sport to "Row Label" field. Drag Differences to "Row Label" field under Sport.
Drag Differences to "Values" field as: Count of Differences (same way the previous question)
Drag Differences to "Values" field (below Count of Differences), and set the mathematical operation as "Average" of Differences (left-mouse click Differences, choose "Values fields settings" and select "Average").
Give a right-click mouse in cell A5 (see picture bellow) and select "Group" option.
Set "Starting at" = 0; "Ending at" = 1000; "By" = 1000 (as in the picture below). Click ok.
You will have in each Sport, the count (frequency) and average Differences values for two groups:
When the Difference B1-C1 is negative; and
When the Difference B1-C1 is zero or positive.
The average of Differences when the score is equal will be always zero.

Resources