LOOKUP function in Excel to search values on left and right - excel

The scenario I'm facing is that in my company we have mixed naming conventions for servers and workstations like:
COUNTRYCODE-WORKSTATION1
WORKSTATION10-COUNTRYCODE
COUNTRY-SERVER1
SERVER1-COUNTRYCODE
So sometimes I may find names like: BR-WK1 or SRV42-US.
I need to create a PivotTable to extract the amount of events per country so I need to come up with a Lookup function that looks at the first two characters in a cell and if it finds a country code it returns the country code in a country column for that row. If it does not find a country code, it looks at the first two characters on the right, and so on. Country code list will be available in another sheet.
IF(LEFT(CELL,CHARNUMBER){COUNTRY LIST}) then (CELLCOUNTRY == {MATCH COUNTY}))
ELSE(RIGHT(CELL,CHARNUMBER){COUNTRY LIST} then (CELLCOUNTRY == {MATCH COUNTRY}))
Excel:
COUNTRY MACHINE NAME EVENT DATE TIME
BR BR-WK1 Critical type 1 08/01/2015 01:15
US SRV42-US Critical type 2 08/01/2015 01:15
BR WK100-BR Warning type 8 08/01/2015 01:15
US US-SRV420 Critical type 1 08/01/2015 01:15
Pivot table:
Row Labels Count of EVENT
BR 2
US 2
Grand Total 4

Related

Excel - getting a value based on the max value off another row in a Table

I'm looking for a solution for a problem I'm facing in Excel. This is my table simplified:
Every sale has an unique ID, but more people can have contributed to a sale. the column "name" and "share of sales(%)" show how many people have contributed and what their percentage was.
Sale_ID
Name
Share of sales(%)
1
Person A
100
2
Person B
100
3
Person A
30
3
Person C
70
Now I want to add a column to my table that shows the name of the person that has the highest share of sales percentage per Sales_ID. Like this:
Sale_ID
Name
Share of sales(%)
Highest sales
1
Person A
100
Person A
2
Person B
100
Person B
3
Person A
30
Person C
3
Person C
70
Person C
So when multiple people have contributed the new column shows only the one with the highest value.
I hope someone can help me, thanks in advance!
You can try this on cell D2:
=LET(maxSales, MAXIFS(C2:C5,A2:A5,A2:A5),
INDEX(B2:B5, XMATCH(A2:A5&maxSales,A2:A5&C2:C5)))
or just removing the LET since maxSales is used only one time:
=INDEX(B2:B5, XMATCH(A2:A5&MAXIFS(C2:C5,A2:A5,A2:A5),A2:A5&C2:C5))
On cell E2 I provided another solution via MAP/XLOOKUP:
=LET(maxSales, MAXIFS(C2:C5,A2:A5,A2:A5),
MAP(A2:A5, maxSales, LAMBDA(a,b, XLOOKUP(a&b, A2:A5&C2:C5, B2:B5))))
similarly without LET:
=MAP(A2:A5, MAXIFS(C2:C5,A2:A5,A2:A5),
LAMBDA(a,b, XLOOKUP(a&b, A2:A5&C2:C5, B2:B5)))
and here is the output:
Explanation
The trick here is to identify the max share of sales per each group and this can be done via MAXIFS(max_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...). The size and shape of the max_range and criteria_rangeN arguments must be the same.
MAXIFS(C2:C5,A2:A5,A2:A5)
it produces the following output:
maxSales
100
100
70
70
MAXIFS will provide an output of the same size as criteria1, so it returns for each row the corresponding maximum sales for each Sale_ID column value.
It is the array version equivalent to the following formula expanding it down:
MAXIFS($C$2:$C$5,$A$2:$A$5,A2)
INDEX/XMATCH Solution
Having the array with the maximum Shares of sales, we just need to identify the row position via XMATCH to return the corresponding B2:B5 cell via INDEX. We use concatenation (&) to consider more than one criteria to find as part of the XMATCH input arguments.
MAP/XLOOKUP Solution
We use MAP to find for each pair of values (a,b) per row, of the first two MAP input arguments where is the maximum value found for that group and returns the corresponding Name column value. In order to make a lookup based on an additional criteria we use concatenation (&) in XLOOKUP first two input arguments.

How to group multiple cells with the same values in Excel

I am trying to group multiple cells in Excel to give me an end value of the total of times those three cells exist, for example, if the Country is "UK", the Method is "Method1" and Weight is "400", instead of that appearing 2 times as it does in the table below, I would like to merge it so it is there only once, but the Amount column has a value of "2" to represent how many times it is in the Sheet. The data I am using has thousands of different and varying values. I am using Microsoft Excel 2016.
Thank you.
Current Sheet:
Country Method Weight Amount
USA Method7 200 x
UK Method1 400 x
UK Method1 400 x
FRANCE Method55 3994 x
Desired Sheet:
Country Method Weight Amount
USA Method7 200 1
UK Method1 400 2
FRANCE Method55 3994 1
This is how my original data looks like:
And I can resume it as you need using Pivot Tables
Make sure you set the Pivot Table Value Property as count when
using the field Amount
Just in case it may help, I'm attaching how I set up this Pivot Table to make the operations you need (please, note my Excel is in Spanish, but position of each field must be the same, and the operation in Values section affecting field Amount must be COUNT)
As there is a direct link between country, method and weight, you can use subtotals for that (menu "Data", chapter "Outline", feature "Subtotals"). You configure it as:
At each change in : "Country"
Use function : "Count"
Add subtotal to:
Country (No)
Method (No)
Weigth (No)
Amount (Yes)
Replace current subtotals (Yes)
Page break between groups (No)
Summary below data (Yes)
Your result will look as follows:
By clicking on the numbers 1, 2 or 3 in the left margin, you'll be able to view/hide subtotals for that country.

Merge multiple rows based on column & sum time values in Excel for MAC

I have a report pulled from KRONOS daily and emailed to me which has 4 columns. The names are down the first column, employee ID, type of pay, hours to pay in that order. I just need to combine the hours so that there is one value per row and just one name. I tried using an easy pivot table but that failed for 2 reasons.
I couldn't figure out how to sum duration of hours in 00:00 format
(tried every single option in field settings) either got N/a or the count of instances.
Even if it worked, I would like to figure out how to exclude the 1.00 hour penalty from the type of pay column indicated by "LP CA Meal Penalty"
I tried to paste the actual tables here but it wouldnt let me so below is my best attempt to replicate issue for one employee.
Curt, Cathy 90066408 LP CA Meal Penalty 1.00
Curt, Cathy 90066408 LP Overtime 1.77
Curt, Cathy 90066408 LP Regular 8.00
Result desired:
Curt, Cathy 90066408 = 9.77
Do Not want: Curt, Cathy 90066408 = 10.77
Assuming your data is in Column A:D and result needs to be displayed from Column G,
To get all the unique Names from Column A enter the following formula in Cell G2
=IFERROR(INDEX($A$2:$A$9,MATCH(0,INDEX(COUNTIF($G$1:G1,$A$2:$A$9),0,0),0)),"")
Drag/Copy down as required. Change range $A$2:$A$9 as per data in Column A.
Now, to get corresponding Employee ID, enter the following formula in Cell H2
=VLOOKUP(G2,A2:D9,2)
or
=INDEX($B$2:$B$9,MATCH(G2,$A$2:$A$9,0))
Finally, to get Total Hours, enter the below formula in Cell I2
=SUMIFS($D$2:$D$9,$A$2:$A$9,G2,$C$2:$C$9,"<>LP CA Meal Penalty")
or
=SUMPRODUCT(($D$2:$D$9)*($A$2:$A$9=G2)*($C$2:$C$9<>"LP CA Meal Penalty"))
See image for reference.
EDIT :
=SUMIFS($D$2:$D$9,$A$2:$A$9,G2,$C$2:$C$9,"<>LP CA Meal Penalty",$C$2:$C$9,"<>LP CA Rest Break Penalty")
or
=SUMPRODUCT(($D$2:$D$9)*($A$2:$A$9=G2)*($C$2:$C$9<>"LP CA Meal Penalty")*($C$2:$C$9<>"LP CA Rest Break Penalty"))
Seems like all you need to do is filter by your third column and exclude in the filter the "LP CA Meal Penalty".
Attached are examples of my result and my filter selection on my pivot table.
Result gotten
Filter excluding the unwanted work hour type from the sum
Let me know if this works for you.
You can use SUMIFS as the example I show you above and the formula to use is:
=SUMIFS($D$2:$D$9,$A$2:$A$9,F2,$C$2:$C$9,"<>"&"LP CA Meal Penalty")
This will exclude LP CA Meal Penalty from the computation.
Also, for the time format, the requirement is not so clear but this is hh:mm what I understand that you want. The formula you can use is:
=TEXT(H2/24,"hh:mm")
Please tweak the range that fits your data structure and let me know if this is what you are asking for.

Excel: Return a single value based on two references

I have two values that a person would enter information for in column B:
Spreadsheet Name: Info
A B
1 Level 2
2 Class Class 2
In a second spreadsheet within the Workbook, i have a data spreadsheet with various tables.
So when a person enters information in !InfoB2 data validation drop down, it would return the name of the table the formula should use to search for the value in the Data table that's level is related to !InfoB2.
Spreadsheet Name: Data
Table Name: Class 1
A B
1 Level BAB
2 --------------------
3 1 8
4 2 3
Table Name: Class 2
A B
1 Level BAB
2 --------------------
3 1 2
4 2 7
So when someone enters Level: 2, and Class2, i would like it to return the value in the BAB column, how can i do this?
Edit
As ghetto as this is, it feels like it's on the right track, however it's returning #VALUE!
VLOOKUP(B1,VLOOKUP(B2,Class,2,FALSE),2,FALSE)
Table Class
Table Name: Class
A B
1 Class Name Table Name
2 Class 1 Class1Table
3 Class 2 Class2Table
You could try the following formula:
=INDEX(INDIRECT(B2&"[#All]"), MATCH(B1,INDIRECT(B2&"[[#All],[Level]]"),0), 2)
This takes the value of B2 (Class2 note I removed the space since table names can't contain spaces) and concatenates it with [#All] so you get: Class2[#All] (this is the table reference). INDIRECT converts the text into a valid range.
INDIRECT(B2&"[[#All],[Level]]") similarly gives the range Class2[[#All],[Level]].
MATCH(B1,Class2[[#All],[Level]],0) gives the row number in which the value in B1 is found (i.e. gives the row in which 2 is found, meaning the result is 4)
=INDEX(Class2[#All], 4, 2) then returns the value from range Class2[#All] in the 4th row and 2nd column.
If I understand correctly you will want to use INDIRECT and/or the structured reference syntax for this one.
I don't have access to Excel at the moment so I can't check to see if this would work. I'll update this answer once I try some stuff out.

Find the top n values in a range while keeping the sum of values in another range under x value

I'd like to accomplish the following task. There are three columns of data. Column A represents price, where the sum needs to be kept under $100,000. Column B represents a value. Column C represents a name tied to columns A & B.
Out of >100 rows of data, I need to find the highest 8 values in column B while keeping the sum of the prices in column A under $100,000. And then return the 8 names from column C.
Can this be accomplished?
EDIT:
I attempted the Solver solution w/ no luck. 200 rows looks to be the max w/ Solver, and that is what I'm using now. Here are the steps I've taken:
Create a column called rank RANK(B2,$B$2:$B$200) (used column D -- what is the purpose of this?)
Create a column called flag just put in zeroes (used column E)
Create 3 total cells total_price (=SUM(A2:A200)), total_value (=SUM(B2:B200)) and total_flag (=(E2:E200))
Use solver to minimize total_value (shouldn't this be maximize??)
Add constraints -Total_price<=100000 -Total_flag=8 -Flag cells are binary
Using Simplex LP, it simply changes the flags for the first 8 values. However, the total price for the first 8 values is >$100,000 ($140k). I've tried changing some options in the Solver Parameters as well as using different solving methods to no avail. I'd like to post an image of the parameter settings, but don't have enough "reputation".
EDIT #2:
The first 5 rows looks like this, price goes down to ~$6k at the bottom of the table.
Price Value Name Rank Flag
$22,538 42.81905675 Blow, Joe 1 0
$22,427 37.36240932 Doe, Jane 2 0
$17,158 34.12127693 Hall, Cliff 3 0
$16,625 33.97654031 Povich, John 4 0
$15,631 33.58212402 Cow, Holy 5 0
I'll give you the solver solution as a starting point. It involves the creation of some extra columns and total cells. Note solver is limited in the amount of cells it can handle but will work with 100 anyway.
Create a column called rank RANK(B2,$B$2:$B$100)
Create a column called flag just put in zeroes
Create 3 total cells total_price, total_value and total_flag
Use solver to minimize total_value
Add constraints
-Total_price<=100000
-Total_flag=8
-Flag cells are binary
This will flag the rows you want and you can grab the names however you want.

Resources