Load item cost from an inventory table - excel

I have an Inventory Sheet that contains a bunch of data about products I have for sale. I have a sheet for each month where I load in my individual sales. In order to calculate my cost of sales, I enter my product cost for each sale manually. I would like a formula to load the cost automatically, using the product name as a search term.
Inventory Item | Cost Sold Item | Sale Price | Cost
Product 1 | 2.99 Product 3 | 16.99 | X
Product 2 | 4.99 Product 3 | 14.57 | X
Product 3 | 6.99 Product 1 | 7.99 | X
So basically I am looking to "solve for X".
In addition to this, the product name on the two tables are actually different lengths. For example, one item on my Inventory Table may be "This is a very, very long product name that goes on and on for up to 120 characters", and on my products sold table it will be truncated at the first 40 characters of the product name. So in the above formula, it should only search for the first 40 characters of the product name.
Due to the complicated nature of this, I haven't been able to search for a sufficient solution, since I don't really know exactly where to start to quickly explain it.
UPDATE:
The product names of my Inventory List, and the product names of my items sold aren't matching. I thought I could just search for the left-most 40 characters, but this is not the case.
Here is a sample of products I have in my Inventory List:
Ford Focus 2000 thru 2007 (Haynes Repair Manual) by Haynes, Max
Franklin Brass D2408PC Futura, Bath Hardware Accessory, Tissue Paper Holder, ...
Fuji HQ T-120 Recordable VHS Cassette Tapes ( 12 pack ) (Discontinued by Manu...
Fundamentals of Three Dimensional Descriptive Geometry [Paperback] by Slaby, ...
GE Lighting 40184 Energy Smart 55-Watt 2-D Compact Fluorescent Bulb, 250-Watt...
Get Set for School: Readiness & Writing Pre-K Teacher's Guide (Handwriting Wi...
Get the Edge: A 7-Day Program To Transform Your Life [Audiobook] [Box set] by...
Gift Basket Wrap Bag - 2 Pack - 22" x 30" - Clear [Kitchen]
GOLDEN GATE EDITION 100 PIECE PUZZLE [Toy]
Granite Ware 0722 Stainless Steel Deluxe Food Mill, 2-Quart [Kitchen]
Guess Who's Coming, Jesse Bear [Paperback] by Carlstrom, Nancy White; Degen, ...
Guide to Culturally Competent Health Care (Purnell, Guide to Culturally Compe...
Guinness World Records 2002 [Illustrated] by Antonia Cunningham; Jackie Fresh...
Hawaii [Audio CD] High Llamas
And then here is a sample of the product names in my Sold list:
My Interactive Point-and-Play with Disne...
GE Lighting 40184 Energy Smart 55-Watt 2...
Crayola® Sidewalk Chalk Caddy with Chalk...
Crayola® Sidewalk Chalk Caddy with Chalk...
First Look and Find: Merry Christmas!
Sesame Street Point-and-Play and 10-Book...
Disney Mickey Mouse Board Game - Duck Du...
Nordic Ware Microwave Vegetable and Seaf...
SmartGames BACK 2 BACK
I have played around with searching for the left-most characters, minus 3. This did not work correctly. I have also switched the [range lookup] between TRUE and FALSE, but this has also not worked in a predictable way.

Use the VLOOKUP function. Augment the lookup_value parameter with the LEFT function.
        
In the above example, LEFT(E2, 9) is used to truncate the Sold Item lookup into Inventory Item.

Related

Complex Multi-Conditional IF Function, return value

I need some help returning a desired figure with a complex formula. I've included a sample table with some dummy data, and have almost reached the solution which returns the correct true/false conditions but need some help printing the figure. My brain is a bit frazzled after working on this for a while...
PROBLEM:
I need to print the figure (6000/3000/0) based on not only calculation rule, but also return 0 if the calculated was already printed at the first instance.
RULES
Method Saving (Column E) is calculated using the methodology:
For each university with the same Product (col B), and same Agreement Year (col C), where Total (col D) returns: (6,000 if over 12,500 / 3,000 if under 12,500 / 0 if total = 0)
That is quite easy to achieve ^ -- however, the tricky part comes in when trying to only print the method saving figure once for each entry of the same university, same product and same agreement year.
Looking at the example table below, rows 2 & 3 both have the same university, product and agreement year. It's quite easy to produce a formula with multiple IF statements to print the calculation of either 6000/3000/0, however I only want to print the method saving figure once, at the first instance, following that the method saving figure should be 0.
Worth noting that in Row # 4, 6000 will be printed because even though University and Product are the same, the Agreement Year is different.
Row 1
University (col A)
Product (col B)
Agreement Year (col C)
Total (col D)
Method Saving (col E)
2
Manchester University
Photoshop
2022-2023
20,000
6,000
3
Manchester University
Photoshop
2022-2023
20,000
0
4
Manchester University
Photoshop
2021-2022
14,000
6,000
5
Manchester University
Photoshop
2021-2022
14,000
0
6
Oxford University
Illustrator
2022-2023
8,000
3,000
7
Cambridge University
Figma
2022-2023
0
0
8
Cambridge University
Linux
2022-2023
13,000
6,000
9
Bristol University
Linux
2022-2023
0
0
10
Coventry University
Lightroom
2021-2022
20,000
6,000
11
Coventry University
Lightroom
2022-2023
10,000
3,000
12
Coventry University
Lightroom
2022-2023
10,000
0
13
Coventry University
Photoshop
2022-2023
4,000
3,000
I have already worked on a potential solution, which may not be the most efficient, but for times sake it has gotten me the furthest. I've edited the cell references to match the dummy data table.
=IF(OR(AND(E1<>"",B2<>B1,C2<>C1),AND(E1<>"",D2=D1,C2<>C1)),
OR(AND(A2=A1,B2=B1,D2<12500,D2<>0),3000,
OR(AND(A2<>A1,B2<>B1,D2<12500,D2<>0),3000,
OR(AND(A2=A1,B2<>B1,D2<12500,D2<>0),3000,
OR(AND(A2<>A1,B2=B1,D2<12500,D2<>0),3000,
OR(AND(A2=A1,B2=B1,D2>12500,D2<>0),6000,
OR(AND(A2<>A1,B2<>B1,D2>12500,D2<>0),6000,
OR(AND(A2=A1,B2<>B1,D2>12500,D2<>0),6000,
OR(AND(A2<>A1,B2=B1,D2>12500,D2<>0),6000,
OR(D2=0,0,0))))))))),0)
The above formula when entered will correctly return TRUE or 0 based on the criteria above, so it has managed to figure out the logic behind it -- I'm just now having trouble at the very end to print the respective figure (6000/3000/ or importantly 0 if either Total is 0 or the figure has already been printed)
Let me know if you have any ideas / need me to clarify anything!
Thanks!
Try this in E2 and fill down:
=IF(COUNTIFS($A$2:A2,A2,$B$2:B2,B2,$C$2:C2,C2)=1,VLOOKUP(Sheet3!$D2,{0,0;1,3000;12500,6000},2),0)
I used a lookup table to determine what to return, and a COUNTIF to only return a non-zero if the entry is the first that matches those first three columns.

transform text file to data table using python

I have text data available in the following format:
title:- sell product A,
description:- good quality product, fast service,
title:- sell product B,
description:- long lasting and good quality,
title:- buy product C,
description:- latest, good price
My goal is to get the text values into a dataframe with title and description values in corresponding columns.For example:
title
Description
sell product A
good quality product, fast service
sell product B
long lasting and good quality
buy product C
latest, good price
Edit Ver 1: Read file and Split to two columns
I am assuming that the pattern of your txt file is
title:-followed by data
description:-followed by data
title:-immediately after description line
description:-immediately after title line
If the pattern is not title:- and description:- sequence one after the other, the below code will NOT work.
I also assume there is no line blank line separating the title and description lines. If there are blank lines, I need to exclude the blank lines first before we do the splitting into title and description.
Read the full file into a list, then separate the data into two lists, then strip the leading text and load into pandas. I have added comments to each line so you can see what's being done.
import pandas as pd
with open('abc.txt','r') as f:
data = [line.rstrip() for line in f.readlines()]
#read all rows into a list while also striping \n
#[::2] selects alternate rows, starting from 0. [8:] excludes "title:-"
#adding rstrip(',') removes the trailing "," from the string
title = [d[8:].rstrip(',') for d in data[::2]]
#[1::2] selects alternate rows, starting from 1. [14:] excludes "description:-"
#adding rstrip(',') removes the trailing "," from the string
desc = [d[14:].rstrip(',') for d in data[1::2]]
df = pd.DataFrame({'Title':title,'Description':desc})
print (df)
The output of this will be:
Title Description
0 sell product A good quality product, fast service
1 sell product B long lasting and good quality
2 buy product C latest, good price
For the above example, the source data in abc.txt file is as follows:
title:- sell product A,
description:- good quality product, fast service,
title:- sell product B,
description:- long lasting and good quality,
title:- buy product C,
description:- latest, good price
Edit Ver 2: If title & description rows do not match
If you are unsure of the datafile and want to play it safe, you can create the dataframe as follows:
df = pd.DataFrame({'Title':pd.Series(title),'Description':pd.Series(desc)})
Here's an example:
I modified the input file to be as follows:
title:- sell product A,
description:- good quality product, fast service,
title:- sell product B,
description:- long lasting and good quality,
title:- buy product C,
description:- latest, good price
title:- buy product D,
The output of this will be:
Title Description
0 sell product A good quality product, fast service
1 sell product B long lasting and good quality
2 buy product C latest, good price
3 buy product D NaN
In the above example, the pattern breaks for the last row. We don't have a matching description value for the title. This results in a NaN in the Description column.
Edit Ver 3: Input file has blank line after each row
If your input file has a blank line in between Title and Description rows, then you can add this code immediately after reading the file.
with open('abc.txt','r') as f:
#read all rows into a list while also striping \n
data = [line.rstrip() for line in f.readlines()]
#removing the blank lines from data
data = data[::2]
Input sample file:
title:- sell product A,
description:- good quality product, fast service,
title:- sell product B,
description:- long lasting and good quality,
title:- buy product C,
description:- latest, good price
title:- buy product D,
Output DataFrame:
Title Description
0 sell product A good quality product, fast service
1 sell product B long lasting and good quality
2 buy product C latest, good price
3 buy product D NaN

Attribute extraction from Metadata using Python3

Here is the input:
Magic Bullet Magic Bullet MBR-1701 17-Piece Express Mixing Set 4.1 out of 5 stars 3,670 customer reviews | 300 answered questions List Price: $59.99 Price: $47.02 & FREE Shipping You Save: $12.97 (22%) Only 5 left in stock - order soon. Ships from and sold by shopincaldwell. This fits your . Enter your model number to make sure this fits. 17-piece high-speed mixing system chops, whips, blends, and more Includes power base, 2 blades, 2 cups, 4 mugs, 4 colored comfort lip rings, 2 sealed lids, 2 vented lids, and recipe book Durable see-through construction; press down for results in 10 seconds or less Microwave- and freezer-safe cups and mugs; dishwasher-safe parts Product Built to North American Electrical Standards 23 new from $43.95 4 used from $35.00 There is a newer model of this item: Magic Bullet Blender, Small, Silver, 11 Piece Set $34.00 (2,645) In Stock.
Expected Output:
Title: "Magic Bullet MBR-1701 17-Piece Express Mixing Set",
Customer Rating : "4.1",
customer reviews : "3670",
List Price : $59.99,
Offer Price : $47.02,
Shipping : FREE Shipping
Can anyone please help me?

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/

Excel Graph - Category and Subcategory grouping

I seldom if ever use excel and have no deep understanding of graphs and graphing-related functions. Having said that...
I have dozens of rows of data, composed by 4 columns
column 1 = amount/price (in numbers)
column 2 = description (the what
in text)
column 3 = category (in text)
column 4 = subcategory (in
text)
I want to make a bar graph of my rows of data so that, the end result looks like this:
X axis - categories
Y axis - amount/price
The trick here is for categories NOT to repeat themselves. For example, if our data is something like...
100 | boat purchase | boats | 3 engine boat
200 | boat purchase |
boats | 2 engine boat
500 | plane purchase | planes | 4 engine plane
900 | car purchase | cars | 1 engine car
Then there should only be ONE instance of boats, planes and cars in my graph, under which all associated data would be summed up.
Last but not least, I have seen graphs where, these unique-not-repeated categories, instead of just being one single 'bar' so to speak, are composed of smaller bars. In this case, I want these smaller bars to be the sub categories, so that the end result would look like this:
In that sample image, I first present a 'basic, classic' graph where blue, yellow and red each represent a unique, different category. Right below it is what I want, a 'breakdown' of each category by subcategory where blue/yellow/red each represent an imaginary 3 different subcategories per category.
This means subcategories will repeat themselves for each category, but categories themselves will not.
For clarification, I currently only have 3 main categories and 6 or so sub-categories, but this could change in the future, hence the desire to have this in an automatic/dynamic fashion
Kind regards
G.Campos
EDIT: new image:
Here i my take on it. Unfortunately I can't post the screenshots as I don't have enough posts.
One solution is to use pivot charts put Amount in "Values", Category in "Row Lables", and SubCategory in "Column Labels".
I uploaded relevant images on a free image upload service.
This is our source data:
Amount Decription Category SubCategory
100 boat purchase boats 3 engine boat
200 boat purchase boats 2 engine boat
500 plane purchase planes 4 engine plane
900 car purchase cars 1 engine car
450 boat purchase boats 2 engine boat
110 plane purchase planes 4 engine plane
550 car purchase cars 1 engine car
230 car purchase cars 2 engine car
450 car purchase cars 5 engine car
This is the desired graph (Edit: This has ghost bars):
http://imageshack.us/photo/my-images/849/pivot.gif/
I just read the comment about no ghost graphs. This might be what you are looking for:
http://imageshack.us/photo/my-images/266/pivotnoghost.gif/
Just googled and found something very similar here:
peltiertech.com/WordPress/using-pivot-table-data-for-a-chart-with-a-dual-category-axis/
You need to add http:// ( I can't have more than two hyperlinks due to low number of posts)
I am not sure this will get you exactly where you want but I find in general in excel it is easiest to summarize your graph data on a separate tab.
For sample data like this
you would create a 2nd tab in the sheet that appears something like
the totals are calculated by using the sumif formula
=SUMIF(Data!C:C,Summary!A2,Data!A:A)
For the Category totals
and
=SUMIF(Data!D:D,Summary!E2,Data!A:A)
For the sub category totals (Assuming sub-categories are mutally exclusive). Now that that data is summarized, highlight the cells and insert a column chart for the following charts.
Adding new categories and/or sub categories will require you to add lines to the summary data, and then add series to the charts. You could use a vba macro to automate that task but I suspect that is overkill since your dataset is "dozens" rather than "thousands"

Resources