söndag 27 mars 2016

M-query (get tab data), Synoptics panel

PQScraping2
Picture: How to get data from the tabs: source


Instead of the usual way: Source = Web.Page(Web.Contents("http://financials.morningstar.com/ratios/r.html?t=MSFT

Use this M-code:
let
    Source = Text.FromBinary(Web.Contents("http://financials.morningstar.com/financials/getKeyStatPart.html?&t=XNAS:MSFT")),
    A = Text.Replace(Source, "\", ""),
    B = Text.Replace(A, "display:none", "display:block"),
    C = Web.Page(B),
    Data = C{6}[Data],
    D = Table.TransformColumnTypes(Data,{{"Efficiency", type text}, {"2015-06", type number}, {"2006-06", type number}, {"2007-06", type number}, {"2008-06", type number}, {"2009-06", type number}, {"2010-06", type number}, {"2011-06", type number}, {"2012-06", type number}, {"2013-06", type number}, {"2014-06", type number}, {"TTM", type number}}),
    E = Table.DemoteHeaders(D),
    #"Transposed Table" = Table.Transpose(E),
    #"First Row as Header" = Table.PromoteHeaders(#"Transposed Table"),
    #"Renamed Columns" = Table.RenameColumns(#"First Row as Header",{{"Efficiency", "Period"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Ticker", each "MSFT"),
    #"Reordered Columns" = Table.ReorderColumns(#"Added Custom",{"Ticker", "Period", "Days Sales Outstanding", "Days Inventory", "Payables Period", "Cash Conversion Cycle", "Receivables Turnover", "Inventory Turnover", "Fixed Assets Turnover", "Asset Turnover"})
in
    #"Reordered Columns"

------
Power-Query Tips
* How to Custom-Sort a Table
= Table.Sort(#"Renamed Columns", each List.PositionOf({"infrastrukturTable", "finansTable", "naturTable", "manniskorTable"}, [Area]))

* How to Combine Records
= Table.AddColumn(Coordinates, "Custom.1", each Record.Combine({[#"http://Column1.properties "],[Custom]}))

------------


Picture: explanation


Site with Country Flags

Inga kommentarer: