I want to be able to make the first column in my table pair with all others, making a new row for every combination of the two.
I need to be able to turn this:
A | 1 | 2 | 3
B | 4 | 5 | 6
C | 6 | 7 | 9
Into this:
A | 1
A | 2
A | 3
B | 4
B | 5
B | 6
C | 7
C | 8
C | 9
Is there any way this can be done using just powerquery?
Just unpivot other columns:
unpivot = Table.UnpivotOtherColumns(Source, {"col1"}, "a", "b")[[col1],[b]]
Are they in separate columns? Then load into powerquery, right click first column, choose unpivot other columns.
Are they in a single column separated by |s? Then use below
Right click column, split column by delimiter, Select or enter delimeter --Custom-- |, Split at each occurrence of the delimiter, ignore advanced options
Remove the latter part of the query so that
= Table.SplitColumn(#"Changed Type", "Column1", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Column1.1", "Column1.2", "Column1.3", "Column1.4"}),
becomes
= Table.SplitColumn(#"Changed Type", "Column1", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv))
right Click first Column, unpivot other columns
right Click attribute column, remove column
Assuming data is in Table1 with no column headers or header column of Column1 then code is
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Column1", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv)),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Split Column by Delimiter", {"Column1.1"}, "Attribute", "Value"),
#"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"})
in #"Removed Columns"
Related
Given table below, where the starting date is variable, as it can be start from any date for a month:
Component | Type | Date | AccumulateBalance
A | PO | 31 Jan | 240
A | PO | 1 Feb | 240
B | PO | 28 Jan | 300
B | PO | 29 Jan | 300
A | SO | 31 Jan | 100
A | SO | 1 Feb | 100
I need to calculate the first opening balance given only the accumulated Balance, and it is reset by Component + Type
Component | Type | Date | OpenBalance
A | PO | 31 Jan | 240
A | PO | 1 Feb | 0
B | PO | 28 Jan | 300
B | PO | 29 Jan | 0
A | SO | 31 Jan | 100
A | SO | 1 Feb | 0
Any helps or advice will be very much appreciated!
Thank you
Andrea
You can use a bit of custom PowerQuery code pasted into home ... advanced editor...
Assuming data is loaded into Table1, the third row will add a column that is the minimum date of all rows with matching Component and Type. The fourth row then checks to see if the current row's date matches the minimum; if so it shows the balance, otherwise zero
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Component", type text}, {"Type", type text}, {"Date", type date}, {"AccumulateBalance", Int64.Type}}),
AddMinDateColumn = Table.AddColumn(#"Changed Type", "Earliest Date", (thisrow) => List.Min(Table.SelectRows(#"Changed Type", each [Component] = thisrow[Component] and [Type] = thisrow[Type])[Date]), type date),
#"Added Custom" = Table.AddColumn(AddMinDateColumn, "OpenBalance", each if [Date]=[Earliest Date] then [AccumulateBalance] else 0)
in #"Added Custom"
another way is to select the Component and Type columns, and Group them, using minimum of Date column and AllRows. If you expand the AccumulateBalance column and remove duplicates, that will give you a table of the minimum dates and their values. You can then merge it back into original table matching on Component, Type, and Date, and expand the Balance field. Sample below which can be pasted into Home...advanced editor... Assumes data is loaded into Table1
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Component", type text}, {"Type", type text}, {"Date", type date}, {"AccumulateBalance", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Component", "Type"}, {{"MinDate", each List.Min([Date]), type date}, {"Data", each _, type table}}),
#"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"AccumulateBalance"}, {"Data.AccumulateBalance"}),
Table2= Table.Distinct(#"Expanded Data"),
#"Merged Queries" = Table.NestedJoin(#"Changed Type",{"Component", "Type", "Date"},Table2,{"Component", "Type", "MinDate"},"Table2",JoinKind.LeftOuter),
#"Expanded Table2" = Table.ExpandTableColumn(#"Merged Queries", "Table2", {"Data.AccumulateBalance"}, {"OpeningBalance"})
in #"Expanded Table2"
I am trying to set up a query in a Google sheet that shows a column of data based on the header and then sorts the numerical values in the column and keeps the referencing row. https://docs.google.com/spreadsheets/d/14kQxqck_NbJ195IF3ALOgFIR23K5nKqXRuk47nvUDoo/edit?usp=sharing
I have read through the wiki help on Google Sheets for query and I'm lost of what to do to get the results I want.
=query(TeamNeeds!B1:O39,"where C='"&C1&"'",-1) is what I have currently and I know it isn't close to what I need.
I would like to use the dropdown in C1 and have it show the associated column on the next sheet over and then sort the data with updating referencing titles (FLYING, GROUND, ROCK, etc.)
+------------+
| Pidgey |
+--------+---+
| FIRE | 3 |
+--------+---+
| GROUND | 2 |
+--------+---+
| ICE | 0 |
+--------+---+
=QUERY({TeamNeeds!A1:A, TRANSPOSE(QUERY(TRANSPOSE(TeamNeeds!B1:AC),
"where Col1 = '"&C1&"'", 0))},
"order by Col2 Desc", 1)
=QUERY(QUERY({TeamNeeds!A1:A, TRANSPOSE(QUERY(TRANSPOSE(TeamNeeds!B1:AC),
"where Col1 = '"&C1&"'", 0))},
"order by Col2 Desc", 1),
"offset 1", 0)
Power Query 2016 standalone
I have a table with columns like this
Market | mapped Brand | mapped Subbrand |
name | text 1 | text 2
I need to concatenate columns that contain a word "mapped" into a new column
I'm trying this:
Text.Combine( List.FindText(Table.ColumnNames(Source), "mapped") , " ")
and get result in every row as a concat of column names
mapped Brand mapped Subbrand
and I need a concat of their values
text 1 text 2
You can create a list of the Columns which contain "mapped", then use that list to select the record fields you wish to combine
ColumnsToCombine = List.Select(Table.ColumnNames(Source), each Text.Contains(_, "mapped")),
#"Add Combined Column" = Table.AddColumn(Source, "Merged", each Text.Combine(Record.FieldValues(Record.SelectFields(_,ColumnsToCombine)),", "))
What's the best approach in Parse to return all values of a column based on one item within that column being selected? For example:
Column 1 Column 2
___________________________
a | e
b | f
c | g
d | h
User selects "d" from a UI element, I want to have my app search through this entire class, pinponint "d" and then recognize it is in column 1, then return all values of that column.
Thanks!
How can write a query for Oracle database such that I can find a comma delimited list of values from a column that contains comma delimited list of values. The :parameter passed to sql statement is also a comma delimited values that user selected.
For e.g
We have a column in tables that contains
1 | 'A','B','C'
2 | 'C','A'
3 | 'A','B'
on the web application interface we have multi select box that shows
A
B
C
and allows user to to select one or more items.
I want rows 1 and 2 to show up if they select A and B, If they select A only the all three should show up b/c all rows 1 to 3 have 'A' value in it.
This example will hopefully help and it matches the values irrespective of which order they appear in the string in the DB record.
Create example table:
CREATE TABLE t
(val VARCHAR2(100));
Insert records:
INSERT INTO t VALUES
('1|''A'',''B'',''C''');
INSERT INTO t VALUES
('2|''C'',''A''');
INSERT INTO t VALUES
('3|''A'',''B''');
Check values:
SELECT * FROM t;
1|'A','B','C'
2|'C','A'
3|'A','B'
Check solution for 'A':
SELECT val
FROM t
WHERE REGEXP_LIKE(val, '(A)');
1|'A','B','C'
2|'C','A'
3|'A','B'
Check solution for A and B
SELECT val
FROM t
WHERE REGEXP_LIKE(val, '(A|B).*(A|B)');
1|'A','B','C'
3|'A','B'
If you want to make sure the 1| part of the result isn't matched by anything then you could query using:
SELECT val
FROM t
WHERE REGEXP_LIKE(val, '(.\|.*)(A)');
and
SELECT val
FROM t
WHERE REGEXP_LIKE(val, '(.\|.*)(A|B).*(A|B)');
Hope this helps...
You could use a where clause with varying number of bind values, depending on the number of selected options:
TEST#PRJ> create table t (c varchar2(100));
TEST#PRJ> insert into t values ('2 | ''C'',''A''');
TEST#PRJ> insert into t values ('3 | ''A'',''B''');
TEST#PRJ> select * from t where c like '%''A''%' and c like '%''B''%';
C
----------------------------------------------------------------------------------------------------------------
1 | 'A','B','C'
3 | 'A','B'
TEST#PRJ> select * from t where c like '%''A''%';
C
----------------------------------------------------------------------------------------------------------------
1 | 'A','B','C'
2 | 'C','A'
3 | 'A','B'
If the values are stored in order you could use a single bind value:
TEST#PRJ> select * from t where c like '%''A''%''B''%';
C
-----------------------------------------------------------------------------------------
1 | 'A','B','C'
3 | 'A','B'