Power Query - Merge Pivot Combined Columns into rows - powerquery

Hi, I'm creating a new thread since the problem I'm trying to solve is different to similar solutions which I've tried unsuccessfully.
I have a table with the following structure (see below), column "City" provides a list of cities A,B...D Column "Date 1" provides dates for the 1st date of an event happening at each city. Column "Date 2" provides the dates for the second event at each city.
City
Date 1
Date 2
A
4/4
5/3
B
4/5
5/4
C
4/6
D
4/7
5/5
I'm trying to bring all the dates for both events into a single column as shown in the example below: Column "Date". While I'm able to pivot columns into rows using Power Query's Split function, I'm unable to solve this specific problem since the data across two separate columns "Date 1" and "Date 2".
Any Power Query ideas to solve this would be awesome, thanks in advance everyone!
City
Date
Date
A
4/4
B
4/5
C
4/6
D
4/7
A
5/3
B
5/4
D
5/5

Right click the City column choose "unpivot other columns"
Then remove extra columns, sort, rename columns as needed

Another fairly quick way to do this in the GUI:
Select the date columns and click Merge Columns (under the Transform tab, Text Column section).
Choose a separator, say Semicolon, and click OK to do the merge.
Now choose Split Column > By Delimiter and choose the delimiter you just used (e.g. Semicolon).
IMPORTANT: Under advanced options, choose Split into Rows and click OK.
Filter out any nulls/blanks from the merged column.
#horseyride's suggestion is certainly fewer steps and cleaner code.
let
Source = <Your Data Source Here>
#"Unpivoted Columns" = Table.Unpivot(Source, {"Date 1", "Date 2"}, "Column", "Date"),
#"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns", {"Column"})
in
#"Removed Columns"

Related

Filter for many columns with dynamic data

I need a help.
I am using Tableau for visualisation. Data in my DataBase are structured by unique keys (+1k rows). I need to filtered value from rows by 2 and more columns (2columns+_filter). And this filtered data must be react to other Filters ("category") on My_Dashboard.
What I used:
Combination from Parameter and Calculation Field.
Parameter - includes data from 2 and more columns (I added it manualy).
Calculation Field - based on Contains(Column1, Parameter) OR... to the last column.
But it doesnot work, because Parameter included data what could be excluded by Filters on My_Dashboard.
Is it possible make a "dynamic filter" what will be select data (rows what inludes "value_1" from range column_1-column_3 after applying Filter - "category1" only.
For example - Input:
rows
column_1
column_2
column_3
column_4
row_key_1
value_1
value_5
category_1
row_key_2
value5
value_1
category_2
row_key_3
value_5
category_1
Output:
rows
column_1
column_4
row_key_1
value_1
category_1
Mayth be it possible with SQL addon/plugin, or something other.
Thanks for your help.
I understood how can realise what I want. If you have the same task, what you need:
add two DataBase (or sheets from excel, etc.) and connect them with unique key "first_db_key = second_db_key";
first DataBase sctuctured by horizontal, 1 row with unique key and a lot of columns with value;
second DataBase sctuctured by our target column (included all possible values waht we need) and ofcourse rows with "unique key" from "first DataBase" could be repeated (2 or more).
on you Sheet need to add filter based on "target column" from "second DataBase", after that, add filter to the "Context" and choose "All using this data source" option on "Apply to Worksheets" in context menu (rigth button click on the filter)
on you Dashboard select to show filter what you added before, and in filter menu choose "All Values in Context" option.
Finaly you are get result what you want.

Google Sheet Date and Time Calculation Question

I have a column that has 34 records of Week Day, Month/Day, and Times. I am looking for two formulas that I can use in a table that will give me the count of weekdays and the time duration per day. Eventually, I would like to just copy and past new dates into column A and have the table automatically calculate. Here is my google sheet example. Is there a way to do this without creating helper columns? If not, no big deal. Anything to help automate the process will be helpful.
https://docs.google.com/spreadsheets/d/1C6N94QJyEgm-2yg2SEDOweIU2fk2h2DLydKb-nH-ObE/edit?usp=sharing
enter image description here
Take a look at the Punches tab in the sample sheet below. It shows what I was mentioning about breaking the columns up. Then, using the QUERY() function I was able to populate the table.
https://docs.google.com/spreadsheets/d/1qbLOjTdzISICTKyUp_jK6gZbQCt-OwtDYYy3HNJygeE/edit#gid=1181136581
G6 Formula
=if(isna(query($A$1:$C, "SELECT COUNT(B) WHERE B ='"&F2&"' LABEL COUNT(B) ''",1)),0,query($A$1:$C, "SELECT COUNT(B) WHERE B ='"&F2&"' LABEL COUNT(B) ''",1))
H6 Formula
=if(G2<>0,query($A$1:$C, "SELECT C WHERE B ='"&F2&"' ORDER BY C DESC LIMIT 1 LABEL C ''",1)-query($A$1:$C, "SELECT C WHERE B ='"&F2&"' ORDER BY C LIMIT 1 LABEL C ''",1),0)

PowerQuery: taking the average of each of many columns

I'm new to PowerQuery and I have a table that is essentially a matrix of dates and hours within those days: the first column holds each date and the rest of the columns are labeled 1 through 24. An example is:
Date H1 H2 H3 H4 ...
---- -- -- -- --
Jan 1
Jan 2
Jan 3
...
This is stored in an Excel file that is quite large, so I want to be able to simply query that file and pull subsets of the data. One example is the average hourly number by year. In SQL this would be represented by "SELECT YEAR(Date), AVG(H1), AVG(H2), ... FROM Source Table GROUPBY YEAR(Date)". However, in PowerQuery it seems like you can only use GROUPBY to generate a new column with the grouped result and thus have to repeat the operation x24 in this case, or more if I had data by seconds for example (to be fair, in the SQL query you also have to type out each column if you don't consider scripting solutions). Is there a simpler approach to generate my desired table (essentially collapsing each column to its average), or do I need to manually add each column?
You can unpivot your hour columns and then you only need to group by year and the unpivoted attribute column.
I made a sample table of your data like this and loaded it into power query. I converted the Date column to Year only, Unpivoted Other Columns on the Date column, then Grouped by the Date and Hour column after unpivoting. The result looks like this.
You can of course repivot the data after if you want inside or outside of power query. This is what the code in power query looks like, but this was all created with normal menu options, not written by hand.
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Extracted Year" = Table.TransformColumns(Source,{{"Date", Date.Year, Int64.Type}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Extracted Year", {"Date"}, "Hour", "Value"),
#"Grouped Rows" = Table.Group(#"Unpivoted Other Columns", {"Date", "Hour"}, {{"Average", each List.Average([Value]), type number}})
in
#"Grouped Rows"

Power Query, row by row the sum of the next 3 values

I have a power query table, 1 column with integer values. In another column, the sum of the current row and the other 2 rows should be calculated row (cell) by row (cell). - In plain Excel, I calculate it like this:
B1: = SUM(B1:B3)
B2: = SUM(B2:B4)
B3: = SUM(B3:B5)
...
How can I solve this with Power Query? If an error occurs in the last 2 lines, this is negligible.
Thanks and regards
Guenther
Is this what you're looking for?
If you start with this as your Source table:
Then if you add a custom column set up like this:
You'll get this:
Here's the M code, loading it from a spreadsheet's workbook, where the data is in a table named Table1:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Custom", each List.Sum(List.Range(Source[Column1],[Column1]-1,3)))
in
#"Added Custom"

Google Spreadsheet Dropdown Filter

I have Google spreadsheet with a list of names in a column. (EX: David, Daniel, John, Cooper).
I made a drop down list of those names. Lets say I two more columns with Age and Birthday.
I want to show the age and birthday column information pertaining to 'David' when I choose 'David' from the drop down list.
A drop down list acting as a 'in spreadsheet filter'.
Any way to do this?
Ive tried the =FILTER() and =UNIQUE() but they don't quite get me what I want. Thanks for the help
Assuming you have the drop down list in cell A1 (of sheet 2) and the columns with data are in sheet1
col A names
col B age
col C birthday
in cell B1 (of sheet2)
=QUERY(Sheet1!A1:C, "Select B, C where A = """&A1&""" ", 1)

Resources