PSX data in Excel with Power Query
Excel's Power Query reads JSON from a web address and turns it into a table you can refresh with one click.
Load the screener as a table
- Data → Get Data → From Other Sources → Blank Query.
- Home → Advanced Editor, paste the query below, then Done.
- Close & Load. Refresh any time with Data → Refresh All.
let
Source = Json.Document(Web.Contents("https://api.psxlens.com/v1/screener?inside_kse100=true&limit=100&sort=cap")),
Rows = Table.FromRecords(Source[matches]),
Keep = Table.SelectColumns(Rows, {"symbol", "name", "sector", "price", "change_pct", "dividend_yield", "pe_ttm", "beta_1y", "market_cap_rs"}, MissingField.UseNull)
in
KeepOne stock's daily prices
let
Source = Json.Document(Web.Contents("https://api.psxlens.com/v1/prices/LUCK?limit=250")),
Rows = Table.FromRecords(Source[data]),
Typed = Table.TransformColumnTypes(Rows, {{"date", type date}, {"close", type number}, {"volume", Int64.Type}})
in
Typed