Forum Discussion
How to combine column 1 and column 2 such that all the elements in column 2 move below column 1?
Hi everyone,
I want to combine variable, variable1 and variable2 into one column and value, value1 and value2 into another column which means the total number of rows will be 36. So at the end of the table it will only have 2 columns which is variable and value. May I know how should I do? Thank you.
Anonymous
Create a function from the code above (named "function_")
(inputT_ as table)=> let colNames_ = Table.ColumnNames(inputT_), colNum_ = Table.ColumnCount(inputT_), auxList_ = List.Numbers(0,colNum_/2), auxList2_ = List.Transform(auxList_, each Table.RenameColumns(Table.SelectColumns(inputT_,List.Range(colNames_, _*2,2)),{{colNames_{_*2}, "Value"}, {colNames_{_*2+1}, "Variable"}})), TFinal_ = Table.Combine(auxList2_) in TFinal_Then you can apply it on the query you showed above:
let Source = Web.Page(Web.Contents("https://finviz.com/quote.ashx?t=FB&ty=c&p=d&b=1")), res_ = function_ (Source{0}[Data]) in res_Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
Anonymous
See it all at work in the attached file
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
Hello Anonymous
did any of the answer suit your requirements? If yes, please mark them as solution please
BR
Jimmy
11 Replies
- AlB
Community Champion
Anonymous
Create a function from the code above (named "function_")
(inputT_ as table)=> let colNames_ = Table.ColumnNames(inputT_), colNum_ = Table.ColumnCount(inputT_), auxList_ = List.Numbers(0,colNum_/2), auxList2_ = List.Transform(auxList_, each Table.RenameColumns(Table.SelectColumns(inputT_,List.Range(colNames_, _*2,2)),{{colNames_{_*2}, "Value"}, {colNames_{_*2+1}, "Variable"}})), TFinal_ = Table.Combine(auxList2_) in TFinal_Then you can apply it on the query you showed above:
let Source = Web.Page(Web.Contents("https://finviz.com/quote.ashx?t=FB&ty=c&p=d&b=1")), res_ = function_ (Source{0}[Data]) in res_Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
- AlB
Community Champion
Hi Anonymous
This can probably be done with pivot/unpivot.
Can you share the original table in text format (instead of a screen pic) so that it can be copied
And show also the expected result, what the final table should look like
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
- AnonymousNot applicable
VariableValueVariable1Value1Variable2Value2Column7Column8Column9Column10Column11Column12
Index S&P 500 P/E 32.82 EPS (ttm) 8.43 Insider Own 0.63% Shs Outstand 2.85B Perf Week 1.46% Market Cap 790.44B Forward P/E 26.39 EPS next Y 10.49 Insider Trans -9.62% Shs Float 2.39B Perf Month -0.37% Income 25.28B PEG 1.98 EPS next Q 3.19 Inst Own 79.90% Short Float 0.97% Perf Quarter 5.73% Sales 78.98B P/S 10.01 EPS this Y -15.10% Inst Trans -0.25% Short Ratio 1.25 Perf Half Y 21.89% Book/sh 41.31 P/B 6.7 EPS next Y 12.21% ROA 18.10% Target Price 321.15 Perf Year 35.40% Cash/sh 19.48 P/C 14.21 EPS next 5Y 16.60% ROE 23.30% 52W Range 137.10 - 304.67 Perf YTD 34.85% Dividend - P/FCF 41.19 EPS past 5Y 42.20% ROI 17.40% 52W High -9.15% Beta 1.19 Dividend % - Quick Ratio 5.5 Sales past 5Y 41.50% Gross Margin 81.00% 52W Low 101.88% ATR 7.17 Employees 56653 Current Ratio 5.5 Sales Q/Q 21.60% Oper. Margin 36.40% RSI (14) 52.02 Volatility 2.46% 2.71% Optionable Yes Debt/Eq 0 EPS Q/Q 28.10% Profit Margin 32.00% Rel Volume 0.88 Prev Close 277.00 Shortable Yes LT Debt/Eq 0 Earnings Oct 29 AMC Payout 0.00% Avg Volume 18.64M Price 276.78 Recom 1.80 SMA20 -0.0006 SMA50 0.31% SMA200 14.74% Volume 16,361,201 Change -0.08% - Jimmy801
Community Champion
Hello Anonymous
you can try thi dynamically approach.
First exctract all value and variable columns and transform this list into the real values of you columns. Then combine this two list into one and create with this data your final table. Here an example
let Source = Table.FromRows(Json.Document(Binary.Decompress(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ized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t, #"(blank).4" = _t, #"(blank).5" = _t, #"(blank).6" = _t, #"(blank).7" = _t, #"(blank).8" = _t, #"(blank).9" = _t, #"(blank).10" = _t, #"(blank).11" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}, {"(blank).4", type text}, {"(blank).5", type text}, {"(blank).6", type text}, {"(blank).7", type text}, {"(blank).8", type text}, {"(blank).9", type text}, {"(blank).10", type text}, {"(blank).11", type text}}), #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]), #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Variable", type text}, {"Value", type text}, {"Variable1", type text}, {"Value1", Int64.Type}, {"Variable2", type text}, {"Value2", type text}, {"Variable3", type text}, {"Value3", Percentage.Type}, {"", type text}, {"_1", type text}, {"_2", type text}, {"_3", type text}}), GetVariables = List.Combine(List.Transform(List.Select(Table.ColumnNames(#"Changed Type1"), each Text.Contains(_, "Variable")), each Table.Column(#"Changed Type1", _))), GetValues =List.Combine(List.Transform(List.Select(Table.ColumnNames(#"Changed Type1"), each Text.Contains(_, "Value")), each Table.Column(#"Changed Type1", _))), CreateFinalTable= Table.FromColumns ( { GetVariables, GetValues }, { "Variables", "Values" } ) in CreateFinalTableCopy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
- AlB
Community Champion
Anonymous
See it all at work in the attached file
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
- Jimmy801
Community Champion
Hello Anonymous
did any of the answer suit your requirements? If yes, please mark them as solution please
BR
Jimmy