SQL select cell contents as column for dynamic range - sql

I have a BEFORE table as the initial format and an AFTER table as the ideal format:
Select "Printer:" cells to column with corresponding data
Is it possible to select the corresponding 'Printer:%' above each small table into a left column by some sort of lookup/filter/dynamic rule where the numbered contents will vary in length as we receive this monthly report? I believe the relative ending line of each table will say "Not assigned" which may be able to be used as a stop. Thank you for considering.

Related

Clear a particular column of data table in vb

I have a data table which has 3 columns . I am populating the values of each column separately in a loop which causes the table structure to be in the format as shown in the image. How to clear every column at the beginning of the loop so that all data comes in a proper tabular format. In short I want to have a data table with variable number of rows possible for each column.
To clear every column at beginning of the loop you have two options:
loop all rows
remove column, add column
Depending on the plenty of rows the two options have different performances.
For large amount of rows i prefer the second option.

Table of data want to group, transpose matching values same line

I have a table of data in Excel. Column A contains Names, Column B contains their interest. Each interest has a separate row. I want to take the data from this table and have a single row with the name of the customer and a column for each of their interests. IE RAW Data:
I am looking to take the 4000 row table and grouping by the name. I am unsure how many times each name appears in the list (Once or Fifty times) but I want the interests placed on a single row with each interest in a separate column EG Desired Data:
I have tried the standard transpose....html table....and pivot tables but it will put the interests all in a row along the top regardless if the customer is interested or not and using a record count T/F that means the data sheet in harder to understand then if I leave it as one block and sort by name
Sure I am not alone with this but all searches for the past 2 hrs keep returning pivot/transpose or duplicate items. Any is appreciated
If you don't want to use VBA, you could first add a column, for instance in column C, with the title "InterestNum."
In C2, just put 1.
In C3, put =COUNTIF($A$2:$A2, $A3) + 1. This will find the number interest it is for the person.
Make a lookup column, for instance in column D. In D2, put =A2&C2
Then, make a list of all the people. I assume that you put this list starting in cell A2 of a new sheet. Then put headers starting in B1 so that B1 contains the title "1" and C1 contains the title "2" standing for the interest number and as many columns as you wish.
Then in Cell B2, put the formula =IF(ISNA(MATCH($A2&B$1,data!$D$2:$D$5,0)),"",INDEX(data!$B$2:$B$5,MATCH($A2&B$1,data!$D$2:$D$5,0)))
This assumes that your original data is in the data tab. I only tested with 4 rows, so you would need to change $D$2:$D$5 to have as many rows as you do. This works by looking up a combination of the name and interest number. It first checks to see if that combination exists in the data. If not, it leaves that interest blank. If so, it finds the actual interest by going to the same row of the lookup.
First remove duplicates using standard excel functionality to prevent having the same interest twice for a person.
Now, you could of course use VBA and perform exactly what you need.
However, I suggest that you use the pivot table.
If your data looks something like this...
... just use "Insert | Pivot table" and insert a pivot table to a new worksheet.
Then, configure the columns as follows:
Et voilĂ , there you have all your interests listed only once and if a person shares an interest, there is a "1".
If you would rather use VBA, just comment and I will edit my answer.

Combining different tables in excel by looking up values

Okay, so let's say I have two tables in Excel. I want to create a third table that looks up data from the other two and combines them. I'll explain what I mean
Here is my first table:
It has a number, which is like a primary key, and a corresponding name for each entry.
I also have a second table:
This one just contains some random info, and there's numerous entries. The Client Name is not listed here, but it does have the key for the client that each entry corresponds to.
I want to create a third table that shows me all the Client Info data, but replaces the key with the actual client name. So basically, wherever it sees a key of "1", it'll look that up from the first table and find "Comet" instead.
The desired table would look like this:
What kind of formula would I need to pull data from one table based on a value? Note that all my tables are in different worksheets.
Assuming that the three tables are in Sheet1, Sheet2, Sheet3, this is the formula you need in Sheet3, cell A2
=vlookup(Sheet2!A2,Sheet1!$A2$b$6,2,false)
Copy down as many rows as there are rows in Sheet2
If you need the client info from Sheet2, use this in Sheet3, cell B2 and copy down
=sheet2!B2
As you put an "SQL" tag, I assume that you are also looking for an SQL based answer. So in addition to #teylyn suggestion, you can use the following SQL query if you are working with SQL databases:
SELECT table1.Client_Name, table2.Client_Info
FROM table1
RIGHT JOIN table2 ON table1.ID_Number = table2.ID_Number
Here is what this query does:
The RIGHT JOIN will return all rows from the right table (here table2), with the matching rows in the left table (here table1) according to the condition specified by the ON clause (here, if the ID Number is the same). Then, the SELECT clause will return a table with ONLY the columns specified after the keyword SELECT.

Copy information from one spreadsheet to another based on a single factor

A B C
1. c First Last
2. d First Last
3. e First Last
4. c First Last
5. c First Last
I'm trying copy the information from columns B & C over to another worksheet (tab in the same document) based on the letter in column A. I only want first and last names to be transferred if the letter in Column A is a "c". Is there a formula or macro I can use to do this?
I think the easiest answer is to create a pivot table based on on the data on your first worksheet. You can format the pivot table so that it looks similar to your original spreadsheet and then filter your column A to select only the letter "C".
One thing to be careful of, is that when you select your data range for the pivot table, be sure to select the entire columns. that way you can add more names and the pivot table will pick it up.
A couple of notes of concern in the pivot table options:
turn off the totals and subtotals to make the pivot table look more
like your original spreadsheet
set it to update automatically, so that you don't have to be constantly refreshing
Hope this helps!

Get specific cell in Crystal Report

I have a Crystal Report linked to table Customer in SQL Server database. My report generator will execute SELECT SQL and pass the result table into the report as data source.
In the report, I have a field and I want this field to display the cell data at the specific row index and column index of the table (maybe I know the column name). For example, my field should display cell at row 3, column 2 of the data source.
How can I do this using Crystal Report. The latest version now is 2011.
First off, in order for the row number to have any meaning, you'll need to be querying the table with an ORDER BY clause (by sorting the report). Without it, you can't make any assumptions about the "original order of records" in the DB as there really is none.
There are a few ways to get this field depending on where in the report you want to display it. If you simply want to show it in the details section, you can make use of a simple formula like this
if rownumber = 3 then {table.column}
If you'd like to display it instead in a footer, you could make use of a variable instead:
whileprintingrecords;
numbervar thedatavariable;
if recordnumber = 3 then thedatavariable := {table.column}
Throw that formula in the details section of the report and you're then free to use thedatavariable in your footers.
Now for the column: If the column index is NOT dynamic you can just see which column corresponds... for example, if the table's columns are customer_id, customer_name then column 2 will always just be the customer name. If the index number will change, like via a parameter, you could make a formula like this
select {?colIndexParameter}
case 1 : {table.customer_id}
case 2 : {table.customer_name} ...