Transpose into new columns; Excel - vba

I could use some help in inventorying some online purchases.
I would like the information in column A to be separated into the following:
Vendor name; item description; eBay item #; purchase price; shipping cost; purchase date
example:
ldean747; MEN'S WILLIAM BAY" "; 260725743398; 10.50; 0.00; 01/28/11
I'm getting hung up because some of the products do not have shipping cost (which would be the second dollar amount you see in the picture).
Any easy way to do this rather than going through and copy paste, transpose on each purchase?

You have a couple of challenges here
dynamic data set format: 3 text fields followed by 1 or 2 numeric fields (vertically)
multiple field seperators / delimiters across your data set
1st field: '()''
2nd field: '|'
3rd field: ':'
You could now start to create formulas which extract the relevant parts of each field using functions like =LEFT(), =MID(), =RIGHT(), =SEARCH(), etc. which for some cases (3rd field) is pretty straightforward, for others can get a bit complex ...
Concretely - the fields can be identified as following:
if the cell above is numeric AND I am alpha THEN I am 1st field
if the cell above is 1st field THEN I am 2nd field
if the cell above is 2nd field THEN I am 3rd field
if the cell above is 3rd field THEN I am product cost
if the cell above is numeric AND I am numeric THEN I am shipping cost
numeric / alpha: =TYPE(), extracting substrings seperated by seperation characters is well covered here at SO
Alternatively you could start to write a VBA program that does the same job for you
meta code:
loop through all rows
determine record type
process record type
So give it a try and come back with more questions.

Related

Custom number in MS Access

Am a newbie in Microsoft Access 2016 making a database system for processing loans.
I have made two fields:
ID e.g: 001 with datatype number and
NRC (This is the official National Registration Card number in my country e.g: "123456/78/1" )
I now want to generate a new field:
LoanNumber from the fields 1. ID and 2. NRC mentioned above.
From the examples above, I want this new field to be composed with two parts concatenated together; that is "ID-first part of NRC before the first '/' ".
e.g: LoanNumber : 001-123456
What code in the expression builder will will help me achieve this?
A number datatype value cannot be saved with preceding zeros. Use Format function to manipulate number. This can be done in a query or textbox but not in table because Format function is not available for Calculated field type.
Format([ID], "000-") & Left([NRC], 6)

Formula based on a specific part of data date

I am looking to have a countifs formula count based on the time provided as part of a date. I do not want to manipulate the raw data i just want to ignore the whole number of a date, I need the decimal place to determine if it is greater or less that .6667.
=COUNTIFS(DATA!$C:$C,">="&$A$1,DATA!$C:$C,"<="&$L$1,DATA!$V:$V,"<.6667",DATA!$E:$E,5)
DATA SOURCE: https://docs.google.com/spreadsheets/d/1uGexXFJ-vIngyzjNXJOVhsO_iFfn3E21XojCjwrhH2g/edit?usp=sharing
Desired result will return a the count if UTC time is greater than or less than .6667 (4:00:00 pm(local)). This will allow me to determine if the reviews are atributed to the Lunch or Dinner shift.
To to determine if the reviews are attributed to the Lunch or Dinner shift, your interest should be in time only. So you may safely ignore the date part and thus the DATA!$C:$C,">="&$A$1,DATA!$C:$C,"<="&$L$1 part in your formula.
Basically what is left with are just 2 criteria:
Overall Rating = 5
Submission Time < 0.6667.
That being said, let's try to get the desired solution step-by-step (you may find it extra descriptive, it's just to make sure we are on the same page):
Change column C (Submission Date Time (UTC)) from Text to Date & time format. This can easily be done by omitting "- ". Select the whole column, press Ctrl + H. In the "Find what" field, type "-", leave the "Replace with" field blank, and click "Replace all" button.
Since you are using column V for the <.6667 criteria, put the formula =C2-INT(C2) in row 2 of that column, then copy and populate rest of the rows. This'll get us the time only - that's what we are looking for.
Finally, get the desired result by using the formula:
=COUNTIFS(data!$V:$V,"<.6667",data!$E:$E,5)

Merging two tables while deleting duplicates in the first table and

This is my first post here and your help would be greatly appreciated! I've read a lot of other posts on this site, however I cannot find the answer to my specific question. I tried using VLOOKUP, INDEX, MATCH, Pivottables, etc. However it doesn't work out the way I want.
Background information: for my thesis I'm studying the difference in cost of capital among single segment and multi segment firms. My dataset contains two tables, one with the SIC codes of the firm's segments and one with the corresponding sales of that segment. The issue with these tables is that there are duplicate SIC codes in the first table. I want to remove the duplicates from the first table and simultaneously calculate the sum of the sales of these duplicate SIC codes in the second table.
My data looks as follows:
The SIC codes per segment and the sales per segment:
Input of SIC codes and sales per segment (one company for 20 years)
What I want to do is eliminate the duplicate SIC codes. If I change the table with SIC codes I also need the table with sales to change accordingly. However, the sales of duplicate segments should not be deleted but added to the first duplicate segment. I can computed this manually for one company, however for 1800 companies would this would be very time consuming. The manually computed output for the SIC codes and for Sales looks like this (so I don't need to merge the table, the output is still in two different tables):
Required output for the SIC codes table and Sales table (one company for 20 years
Thanks a lot!
This is the way to go about it. In 2 parts: get a list of unique SIC codes in each row, and, sum up the unique corresponding values to them.
Part I:
General logic to this part: nested INDEX functions.
Let's assume your output table (range including headers A25:J45) is exactly below your main/input table (range including headers A1:J21). Assuming only 20 rows of data, but you can drag the formulae to as many rows.
The first column should always be picking up values from the corresponding first column of input table. A26 =A2 and so on.
For B26, use this formula =INDEX($A2:$J2,MATCH(0,INDEX(COUNTIF($A26:A26,$A2:$J2),0,0),0))
You can drag this formula across to J45/end of output table. (You can use "Evaluate Formula" in excel to understand the workings of the logic)
This should populate your output table with unique SIC codes for each row.
Part II:
General logic to this part: SUM and Arrays
Let's assume your output table (range including headers L25:U45) is exactly below your main/input table (range including headers L1:U21). Assuming only 20 rows of data, but you can drag the formulae to as many rows.
In cell L26, which is the first row, left most element in the output table, you will need an array formula (Ctrl+Shift+Enter). If you don't know what array formula are read here.
Formula for L26 {=SUM(IFERROR($A2:$J2=A26,0)*IFERROR($L2:$U2,0))}.
You will need to enter only this in L26 =SUM(IFERROR($A2:$J2=A26,0)*IFERROR($L2:$U2,0)), and hit Ctrl+Shift+Enter. Excel will put the curly brackets around it on its own self.
Copy paste the formula in the rest of the output table.
Screenshot for reference based on your Excel file.
There is a remove duplicates function in excel 2010 on the Data Tab Screenshot

Counting the no. of commas across multiple fields using SQL

I've 3 fields which contain only text. However, i want to add a calculated field which counts the number of commas in each of these 3 fields and displays it separately in the adjacent column. The snippet of SQL i use is shown below. How can i build the calculated field?
SELECT week, client_I, client_II, client_III
FROM quality_control_test;
Please advise!
well, you can "count" the number of a given character in a string, by using this:
length(c) - length(replace(c,',',''))
I'm assume you can figure out how to leverage that for your own query ;)

How to create calculated column with data from another list

I have the following situation: List A has two columns (Name, Amount) and in List B (Name) I want to add a calculated column which should be the sum of all entries in List A that have the same name as in List B. Example:
List A:
NAME Amount
L0011 100
L0011 50
L0020 234
So in List B I want the calculated column to show:
NAME Amount
L0011 150
L0020 234
How can this be done? Workflow (as soon as I add/mod an entry in List A, update List B) or something else? Thanks
lem.mallari's answer is a huge pain unless you can assume that the Amounts in List A never change, since it's not tracking whether an item has already been added to the sum. There is no way for a Workflow to iterate through a SharePoint list, which means there is no easy way to calculate the sum or average of multiple list items.
The correct way to implement this will will require some development. The SharePoint Developer Training (2010, 2013) will actually get you most of the way there: an event receiver should trigger when items are added or changed in Lists A and B that uses SharePoint's API to go through List A and average values by Name, then update all (or just affected) items in List B. Alternatively, you can use JavaScript to display the sum of all entries in List A that have the same name as the item in List B as long as all the data is displayed on your page. If you're handy with XPath and InfoPath, you could add List A as a secondary data source to List B's form and select only applicable items in List A to sum from.
But if we're talking Workflows, here's the "workflow only" method. This was tested and successful in 2010. Create custom List C with the following columns:
Title (string, mandatory, enforce unique values)
TotalItems (integer, mandatory, default 0)
Sum (number, decimal places however you want, mandatory, default 0)
Average (calculated, =IF(TotalItems=0,0,Sum/TotalItems)) (optional)
Replace the Name columns in Lists A and B with lookup columns pointing at List C. Delete the Amount column in List B, instead including the Sum column as an additional column. Add the following columns to List A, and ensure that users cannot change them directly. This can be restricted by making InfoPath forms or by making alternative view and edit forms.
AmountArchive (number, identical to Amount, default 0)
AmountHasBeenSubmitted (yes/no, default no)
Create a Workflow to run each time an item is created or modified in List A. Use these commands (I'm using a list for readability; it was getting ugly when formatted as code):
If Current Item:Amount not equals Current Item:AmountArchive
Set Variable:Item Count to (Data source: List C; Field from source: TotalItems; Find the List Item: Field Title; Value: Current Item:Name(Return field as: Lookup Value (as Text)))
Calculate Variable:ItemCount plus 1 (Output to Variable: ItemCount)
Calculate List C:Sum (similar settings as above; be sure to use Lookup Value (as Text) and not String!) minus Current Item:AmountArchive (Output to Variable: SumWithoutValue)
Calculate Variable: SumWithoutValue plus Current Item:Amount (Output to Variable: NewSum)
If Current Item:AmountHasBeenSubmitted equals No
Set AmountHasBeenSubmitted to Yes
Update item in List C (Set TotalItems to Variable:ItemCount; Set Sum to Variable:NewSum; Find the List Item in the same way of Field:Title; Value: Current Item:Name(Return field as: Lookup Value (as Text))
Else
Update item in List C (don't do anything to TotalItems; use the same logic to set Sum to Variable:NewSum)
Set Amount to Current Item:AmountArchive
This can't be done using calculated columns because calculated columns can only be used for columns on the same list.
Using SharePoint Designer Workflows you can just use Create List Item and Update List Item actions so that whenever a user adds a value for L0011 the amount will be added in another list's column which contains the previous amounts already.
Let me know if you need a more detailed answer for the SharePoint approach and I'll provide you a step by step instruction on what to do.
What about using the DSum function? https://support.office.com/en-us/article/DSum-Function-08F8450E-3BF6-45E2-936F-386056E61A32
List B
NAME Amount
L0011 =DSum("[Amount]","List A","[NAME]=''" & [NAME] & "'")
L0020 =DSum("[Amount]","List A","[NAME]=''" & [NAME] & "'")