This is best Fabric, Power BI, SQL and AI community event. How do we know? The last event sold out! Save €200 with code FABCMTY200.
Register nowJuly 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more
Hi guys,
I would like to get the stock split history webdata for each ticker. As you can see (1. Data StockSplitHistory), each row is a different ticker so i would expect different output. Now it shows all the same output, probably because in my function the symbol = adtx and that needs to be a variabel according to the specific ticker for each row.
FunctionStockSplitHistory
(Ticker as text) =>
let
Source = Web.Page(Web.Contents("https://www.stocksplithistory.com/?symbol=adtx")),
Data1 = Source{1}[Data],
#"Changed Type" = Table.TransformColumnTypes(Data1,{{"Column1", type text}}),
#"Removed Top Rows" = Table.Skip(#"Changed Type",1),
#"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]),
#"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date", type date}, {"Ratio", type text}})
in
#"Changed Type1"
Maybe i need to work with loops of some sort?
Could you please help me out here?
Thanks a million!
Regards, Eric
Solved! Go to Solution.
Thank you for your reply!
Everything is working now!
@FredF First I wrote a Python script to get all the links:
import requests
from bs4 import BeautifulSoup
import pandas as pd
url = 'https://www.stocksplithistory.com/'
reqs = requests.get(url)
soup = BeautifulSoup(reqs.text, 'html.parser')
tickers = []
for link in soup.find_all('a'):
current_link = link.get('href')
if 'stocksplithistory' in current_link or 'splithistory' in current_link:
tickers.append(current_link)
ticker_df = pd.DataFrame(tickers, columns = ['Ticker'])
ticker_dfThen fixed the function to check for Date and Ratio column as some pages have 2 tables some have 3, your code has hardcoded {1} i.e. Source{1}[Data] which doesn't work for some links.
( TickerLink as text ) =>
let
Source = Web.Page ( Web.Contents ( TickerLink ) ),
AddedCustom =
Table.AddColumn (
Source,
"Custom",
each List.ContainsAll (
List.Combine ( Table.ToColumns ( [Data] ) ),
{ "Date", "Ratio" }
)
),
FilteredRows = Table.SelectRows ( AddedCustom, each ( [Custom] = true ) )[[Data]],
ExpandedData =
Table.ExpandTableColumn (
FilteredRows,
"Data",
{ "Column1", "Column2" },
{ "Column1", "Column2" }
),
ChangedType = Table.TransformColumnTypes ( ExpandedData, { { "Column1", type text } } ),
RemovedTopRows = Table.Skip ( ChangedType, 1 ),
PromoteHeaders = Table.PromoteHeaders ( RemovedTopRows, [ PromoteAllScalars = true ] ),
ChangedType1 =
Table.TransformColumnTypes (
PromoteHeaders,
{ { "Date", type date }, { "Ratio", type text } }
)
in
ChangedType1Finally invoked the function
let
Source = Tickers,
InvokedCustomFunction =
Table.AddColumn (
Source,
"FxGetData",
each try FxAntriksh ( [Ticker] ) otherwise null,
type table [ Date = date, Ratio = text ]
),
RemoveNulls = Table.SelectRows ( InvokedCustomFunction, each [FxGetData] <> null ),
ExpandedFxGetData =
Table.ExpandTableColumn (
RemoveNulls,
"FxGetData",
{ "Date", "Ratio" },
{ "Date", "Ratio" }
)
in
ExpandedFxGetDataIf you can't use Python for xyz reason then I have hardcoded the values in a separate query TickersHardCoded.
Finally, the code is slow, so it will take 5-10 minutes to complete the refresh.
Here is the link to the PBIX - https://drive.google.com/file/d/1o4vSUyQP0Ex-GcsLPEZLDsjGx800k4eG/view?usp=sharing
Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.
If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!
Check out the July 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 |