ETL transpose and cross join part of a table in SQL or Excel - sql

I have an Excel spreadsheet that I need to import into a database. The data in the spreadsheet is of the following format.
I want to transform the 10 Wk columns into two columns: Week and Value. An example of this transformation I'd like is below (this is just the transformation of the first 3 rows in the table above).
Does anyone have any tips on making a transformation like this (either in SQL or Excel)? Ultimately I need to come up with a process to take the data from the spreadsheet of the format in the first table, transform it to look like the second table and load it into a Teradata database. I'm open to doing the transform process using SQL code, Excel or even Python code. Any help/suggestions is much appreciated. Thank you in advanced!

Related

Column with multiple data types in Power BI Matrix Table

My issue is similar to this one Multiple data types in a Power BI matrix but I've got a bit of a different setup that's throwing everything off.
What I'm trying to do is create a matrix table with several metrics that are categorized as Current (raw data values) and Prior (year over year percent growth/decline). I've created some dummy data in Excel to get the format the way I want it in PowerBI (see below):
Desired Format
As you can see the Current values are coming in as integers and the Prior % numbers as percentages which is exactly what I want; however, I was able to accomplish this through a custom column with the following formula:
Revenue2 = IF(Scorecard2[Current_Prior] = "Current", FORMAT(FIXED(Scorecard2[Revenue],0), "$#,###"), FORMAT(Scorecard2[Revenue], "Percent"))
The problem is that the data comes from a SQL query and you can't use the FORMAT() function in DirectQuery. Is there a way I can have two different datatypes in the same column of data? See below for how the SQL data comes into PowerBI (I can change this if need be):
SQL
Create 2 separate measures, one for the Current second for Prior, and format these measures.
Probably you can also use a case in SQL query to format your data to bring it as STRING.
What I wound up doing was reformatting the SQL code to look like this:
Solution
That way Current/Prior are have two separate values and the "metric" is categorical.
I got the idea from this post:
Simple way to transpose columns and rows in SQL?

Formatting Text Data from one Column into Multiple columns

I have been working on this for 2 days and I have no had luck finding out how to do this.
I have a single column that contains data that I need to format.
Here is an image showing what I'm looking for. I'm using Excel 2013 and MS SQL Server 2012 Enterprise. I have the latest version of Power BI.
What I have What I want
I haven't dealt with data in this type of format before and I'm not a SQL guru so I'm looking for some help. I can't find anything online that is similar to my situation. I will use any tool that can do this. I've tried Excel, SQL, Power BI with no luck so far. I'm sure its something simple.
Thanks for your help.
I would tackle this in the Edit Queries window of Power BI. You should be able to achieve this by clicking around that window - no code is needed.
First I would add 3 Conditional Columns to split your data out, e.g.
Computer Name
if [Column1] begins with Machine Then (column) Column1
Repeat for the other 2 columns. Then select the Computer Name column and choose Transform / Fill / Down. Finally select the Computer Name column and choose Transform / Group By. Add aggregations for Max Status and Max Encryption.

Filter certain SQL data formatted in one column into a new column

Before I begin I found this to be most relevant with the research I have done.
How to split the data from one column into separate columns using the contents of another column in SQL
Attached are pictures of my progress so far. How can I display this information such as it is shown in the excel file without disrupting the GROUP BY filter in my Query?
It's a Fishbowl Database, newest version. I am running the queries through Flamerobin which you see in the picture. Trying to organize the query to display correctly so I can format it into 'iReports' and export it into an excel spreadsheet like the one shown. Maybe there is some part of this that would better be done in excel?
Notice the numbers for Qty are different, that's ok right now.
My reputation is too low to post pictures I am sorry. Here are the two JPGs in my Dropbox. I really appreciate the help.
https://www.dropbox.com/sh/r2rw5r2awsyvzs9/AAAXXg27CMPOYtZFqPX3Dx6la?dl=0

excel vba sql select data with long data type

I have an excel marco script to generate db data to do comparison, I found that excel cannot display whole Long data type content that return from sql statement (only return few letter).
How can I write the sql so that excel can display all contenet in Long data type?
Thanks!!
Please take a look here at the limitations of Excel
If it is a possability for you, I would try to select your data into several columns
Select left(string, Len(string)/2), right(string, Len(string)/2) from table
You may take a look at refernce for this here
You may also insert an if clause to only split if its over a specific value (e.g. the Excel cell max)

sorting BIG excel data

Right so, I have been given a LOT of "consumer data" to sort, 3 excel files, each containing multiple worksheets, up to 7 worksheets, each up to 1M rows (max worksheet size in excel 2013 is just over 1 rows)
I need to pull out of these all people within a region, so have a list of post codes in this region (say 30 post code areas)
How can I achieve this most easily?
If the data was in SQL server, i'd just write a long SQL statement selecting all where postcode LIKE 'B75'% OR 'B74'% etc etc.
But in excel I can only run a "filer" on one worksheet at a time... (I think)
Is it going to be easiest to throw all the data into sql server, or have I overlooked a method?
First solution is to let Excel do the task of sorting for you. You need to add filters to columns and select Sorting options.
Other solution is to Export Data to SQL Table(s). To do this, Open SQL Management Studio, Right Click on Database to which you want to export data to and Select "From Excel File". Do this for each Excel file you have. After importing all data in Database, sort Data using SQL Query.
Second Solution is reliable but first solution is faster. You need to decide which one you should select.