How to extract specific text from a field in Excel? - excel

I have the following sample of data where I want to extract a specific text from the Order description field.
For example:
There are 3 records of sales with the same Order ID and Invoice ID, however, the Order Amount does not reflect the true total for each of these sales records.
Is there a way for me to extract the cost of items out from Order Description column in Excel? Please do share the formulas if there is any!
Thanks!

Well, you could use FILTERXML:
Formula in B2:
=INDEX(FILTERXML("<t><s>"&SUBSTITUTE(SUBSTITUTE(A2,",","")," ","</s><s>")&"</s></t>","//s[starts-with(., '$')]"),1)
If you don't have Excel O365, you could strip off the INDEX(). I have it in there to take the first amount from the resulting array of amounts to prevent spilling it.

If all your data follows same structure (that means the price starts with $ and it ends with , ) you can do it like this:
=MID(A1;SEARCH("$";A1);SEARCH(", ";A1)-SEARCH("$";A1))
EDIT: Wrap everything inside a VALUE function, so the output will be a number.

Related

Extracting text in excel

I have some text which I receive daily that I need to seperate. I have hundreds of lines similar to the extract below:
COMMODITY PRICE DIFFERENTIAL: FEB50-FEB40 (APR): COMPANY A OFFERS 1000KB AT $0.40
I need to extract individual snippets from this text, so for each in a seperate cell, I the result needs to be the date, month, company, size, and price. In the case, the result would be:
FEB50-40
APR
COMPANY A
100
0.40
The issue I'm struggling with is uniformity. For example one line might have FEB50-FEB40, another FEB5-FEB40, or FEB50-FEB4. Another example giving me difficult is that some rows might have 'COMPANY A' and the other 'COMPANYA' (one word instead of two).
Any ideas? I've been trying combinations of the below but I'm not able to have uniform results.
=TRIM(MID(SUBSTITUTE($D7," ",REPT(" ",LEN($D7))), (5)*LEN($D7)+1,LEN($D7)))
=MID($D7,20,21-10)
=TRIM(RIGHT(SUBSTITUTE($D6,"$",REPT("$",2)),4))
Sometimes I get
FEB40-50(' OR 'FEB40-FEB5'
when it should be
'FEB40-FEB50'`
Thank you to who is able to help.
You might get to the limits of formulas with this scenario, but with Power Query you can still work.
As I see it, you want to apply the following logic to extract text from this string:
COMMODITY PRICE DIFFERENTIAL: FEB50-FEB40 (APR): COMPANY A OFFERS 1000KB AT $0.40
text after the first : and before the first (
text between the brackets
text after the word OFFERS and before AT
text after 'AT`
These can be easily translated into several "Split" scenarios inside Power Query.
split by custom delimiter : - that's colon and space - for each ocurrence
remove first column
Split new first column by ( - that's space and bracket - for leftmost
Replace ) with nothing in second column
Split third column by delimiter OFFERS
split new fourth column by delimiter AT
The screenshot shows the input data and the result in the Power Query editor after renaming the columns and before loading the query into the worksheet.
Once you have loaded the query, you can add / remove data in the input table and simply refresh the query to get your results. No formulas, just clicking ribbon commands.
You can take this further by removing the "KB" from the column, convert it to a number, divide it by 100. Your business processing logic will drive what you want to do. Just take it one step at a time.

Add x Days to a Date Based on vlookup Output Excel

What I'm trying to do is give a due date based on an input date, type of review, and department.
For example if the department is ABC and the review is retrospective, the due date will be the input date + 30 days.
But if the department is ABC and the review is concurrent, then the due date will be input date + 1 day.
I know I can concatenate the department and review into the vlookup table but I'm not so sure how to get the output to be the due date that I want.
Can anyone help?
EDIT:
Per the first answer below, I hashed out an input table with concatenated columns just in case I needed them. It is a bit more complicated than I originally thought.
Input table with date logic
I'd love to simply edit the source data but the report isn't readily available in the database. Could I still use the suggestions below?
Assuming you have a lookup table for the number of days to add depending upon the department and review type similar to the one below, you can use an INDEX/MATCH/MATCH and simply add it to the input date:
=$A2+INDEX($H$4:$J$5,MATCH($B2,$G$4:$G$5,0),MATCH($C2,$H$3:$J$3,0))
SOLUTION FOR AN ALTERNATIVE LOOKUP TABLE LAYOUT
If your layout table is more like as below, you can use a MINIFS formula (or MAXIFS if you would prefer):
=$A2+MINIFS($I$3:$I$8,$G$3:$G$8,$B2,$H$3:$H$8,$C2)

Sum multiple values in Index/Match function

I am working on a distribution problem, analysing the volumes delivered to a set of stores (75 stores).
I have an Excel file as follows:
As you can see, each day does not contain the same stores, given that each store does not receive a delivery every day.
I want to get a new table that has the code of the store in the columns, and the information about volume and miles in the rows. Furthermore, I want to sum the values of the volumes given that they belong to the same store. In this example this would look like this:
As you can imagine, my spreadsheet is way bigger, having a total of 6500 rows and 800 columns. I was thinking about using the function combination of INDEX/MATCH, but I cannot see how to make it sum the multiple values for a given store in a given date.
While you need to extend this formula, you could use:
=SUMIF(INDEX($C:$F,MATCH($J2,$A:$A,0),),L$1,INDEX($C:$F,MATCH($J2,$A:$A,0)+MOD(ROW(),2)+1,))
if the table is build up like this:
From L2 you can simply drag down and to the left as needed ;)
EDIT
To also get the stores:
L1: {=MIN(IF(MOD(ROW($C$1:$F$6),3)=1,$C$1:$F$6))}
This is an array formula and must be entered without the {} but being confirmed with ctrl+shift+enter!
M1: =SUMPRODUCT(SMALL(IF(MOD(ROW($C$1:$F$6),3)=1,$C$1:$F$6),SUM((IF(MOD(ROW($C$1:$F$6),3)=1,$C$1:$F$6)<=L$1)*1)+1))
from M1 you can simply copy to the right.
And to get the dates (if non continuous or something like that)
J2: =MIN(A:A)
J3: =J2
J4: =SMALL(A:A,COUNTIF(A:A,"<="&J3)+1)
J5: =J4
then copy J4:J5 simply down :)
Dont put the stores in the columns, use VBA or similar to read the input files and normalize the data so that the output would be a table looking like
Store - Date - Volume - Miles
101 10/06/2016 520 120
102 11/06/2016 500 100
Then you can always lookup a store and date or pivot the data later.

Excel to auto-remove duplicates before sum in CSV based on URL-paramter

I am using Really Simple Traffic Logger to store Date, Timestamp, IP and visited site by users on my website. Each user visiting the website is assigned a UID by a parameter in the URL in the form of:
http://www.domain.com/site.php?=dTM_c1_uid7
dTM = customer,
c1 = category 1,
uid7 = uid for person 7
The csv file stored contains the following:
"DATE","TIME","IP","LOOKING_FOR"
"2016-05-22","07:30:40","XX.XX.XX.XX","/site.php?=dTM_c1_uid7"
"2016-05-22","07:31:10","XX.XX.XX.XX","/site.php?=dTM_c1_uid7"
"2016-05-22","07:31:19","XX.XX.XX.XX","/site.php?=dTM_c1_uid8"
the information is stored in a CSV-file, where I am attempting to sum the results of the data, which is to be visualized by another script in real-time. However, as many of the visitors are the same people visiting the website more than once, I would like to remove these based on the UID parameter in the URL, before calculating the sum, so each count (hit) can be calculated as unique hits.
I am therefore trying to work out a formula for auto-removing duplicates that contains the "_uid7" parameter, before calculating the sum.
Is there a smart method for constructing a formula in excel that can do that automatically?
Thank you.
Supposing your data starts from A1 Please post the following formula in B1and fill down the column B with data in column A
=TRIM(SUBSTITUTE(MID(A1,(SEARCH("dTM_c1_",A1,1)+7),99),CHAR(34),REPT(CHAR(32),99)))
You will get uid7, uid8 etc which can be counted or other processing can be done.
EDIT
Based on your comments and taking "dTM_c1_uidnn.." string counts of occurrence is shown in the following snapshots. I have shown two snap shots out of which one hides the helper column.
This is the best I could do at the moment. Column B can be filtered either with Excel native Remove Duplicates OR by a VBA routine. Finding unique values of numerical values is comparatively easy using Frequency Function But somehow after repeated attempts despite following some tutorials, I could not get the desired results for text strings. I would appreciate your feedback positive or negative. My efforts would continue to find the most optimal solution.

In Excel, how can i break ties when ranking students' tests?

I'm doing like a bit of a competition for my students in which they have a weekly test they have to complete and submit. The grade is stored in an excel column next to their names.
Following instructions i found, i was able to create a full working general TOP3 with the Average of the tests' grade and when i get to the TOP5 for the grades of the last submitted test, i get a three-way tie.
I use the LARGE function to find the top grades and the combination of the INDEX and MATCH functions to find and display the name associated to that mark.
(Something like this =INDEX($A$1:$A$29;MATCH(M12;$F$1:$F$29;0))
The problem is that the function compares the grade on it's left to find that value in the range of grades and then returns the corresponding name associated to that row; so, it returns the same name for the three grades.
I tried using an IF function to exclude the first-result-cell from the array in which the formula is looking so that when it finds a match it will be different from the previous one, but i have not manage to work it out...
You need to use a pivot table and filter the results to the top 3. A pivot table will display the ties.
Here is a link that #Jeeped gave which basically solves the problem!
Thank you all for commenting!
Multiple Ranked Returns from INDEX(…) with Duplicate Values:
http://tinyurl.com/naavhgf

Resources