Forum Discussion

Mekist's avatar
Mekist
Helper III
7 months ago
Solved

If There is No Data, Continue

Hello

I am pulling price information from companies; if there is no data for the company, it throws an error and does not proceed. When it encounters an error, can it continue and move on to the next company?

With price data

https://www.isyatirim.com.tr/_layouts/15/Isyatirim.Website/Common/Data.aspx/HisseTekil?hisse=ASTOR&startdate=12-06-2024&enddate=14-06-2024

Without price data

https://www.isyatirim.com.tr/_layouts/15/Isyatirim.Website/Common/Data.aspx/HisseTekil?hisse=ZGYO&startdate=12-06-2024&enddate=14-06-2024

 

query

let
    Kaynak = (produceName as text) as table =>
let
    baseUrl = "https://www.isyatirim.com.tr",
    relativeUrl = "/_layouts/15/Isyatirim.Website/Common/Data.aspx/HisseTekil",
    queryParams = [
    hisse = produceName,
    startdate = "31-03-2023", //Date.ToText(Date.AddDays(Date.From(DateTime.LocalNow()), -700),"dd-MM-yyyy"),  // Bugüneden geriye doğru istediğimiz tarihe gidiyoruz
    enddate = DateTime.ToText(DateTime.LocalNow(), "dd-MM-yyyy") // günün tarihini yazdırıyoruz
    ],
    Kaynak = Json.Document(Web.Contents(baseUrl, [RelativePath = relativeUrl, Query= queryParams])),
    // Orijanl link "https://www.isyatirim.com.tr/_layouts/15/Isyatirim.Website/Common/Data.aspx/HisseTekil?hisse=ISMEN&startdate=12-06-2024&enddate=14-06-2024"
    value = Kaynak[value],
    #"Tabloya Dönüştürüldü" = Table.FromList(value, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Genişletilen Column1" = Table.ExpandRecordColumn(#"Tabloya Dönüştürüldü", "Column1", {"HGDG_TARIH", "HGDG_KAPANIS","DOLAR_BAZLI_FIYAT", "HGDG_HACIM"}, {"Column1.HGDG_TARIH", "Column1.HGDG_KAPANIS","Column1.DOLAR_BAZLI_FIYAT", "Column1.HGDG_HACIM"})
in
    #"Genişletilen Column1"
in
    Kaynak

 

let
    Kaynak = Web.BrowserContents("https://www.isyatirim.com.tr/tr-tr/analiz/hisse/Sayfalar/Temel-Degerler-Ve-Oranlar.aspx#page-1"),
    #"Html'den Ayıklanan Tablo" = Html.Table(Kaynak, {{"Column1", "TABLE[id='summaryBasicData'] > * > TR > TH[colspan=""1""][rowspan=""1""]:nth-child(1):nth-last-child(8), TABLE[id='summaryBasicData'] > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(8)"}, {"Column2", "TABLE[id='summaryBasicData'] > * > TR > TH[colspan=""1""][rowspan=""1""]:nth-child(1):nth-last-child(8) + TH[colspan=""1""][rowspan=""1""]:nth-child(2):nth-last-child(7), TABLE[id='summaryBasicData'] > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(8) + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(7)"}, {"Column3", "TABLE[id='summaryBasicData'] > * > TR > TH[colspan=""1""][rowspan=""1""]:nth-child(1):nth-last-child(8) + TH[colspan=""1""][rowspan=""1""]:nth-child(2):nth-last-child(7) + TH[colspan=""1""][rowspan=""1""]:nth-child(3):nth-last-child(6), TABLE[id='summaryBasicData'] > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(8) + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(7) + TD:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(6)"}, {"Column4", "TABLE[id='summaryBasicData'] > * > TR > TH[colspan=""1""][rowspan=""1""]:nth-child(1):nth-last-child(8) + TH[colspan=""1""][rowspan=""1""]:nth-child(2):nth-last-child(7) + TH[colspan=""1""][rowspan=""1""]:nth-child(3):nth-last-child(6) + TH[colspan=""1""][rowspan=""1""]:nth-child(4):nth-last-child(5), TABLE[id='summaryBasicData'] > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(8) + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(7) + TD:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(6) + TD:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(5)"}, {"Column5", "TABLE[id='summaryBasicData'] > * > TR > TH[colspan=""1""][rowspan=""1""]:nth-child(1):nth-last-child(8) + TH[colspan=""1""][rowspan=""1""]:nth-child(2):nth-last-child(7) + TH[colspan=""1""][rowspan=""1""]:nth-child(3):nth-last-child(6) + TH[colspan=""1""][rowspan=""1""]:nth-child(4):nth-last-child(5) + TH[colspan=""1""][rowspan=""1""]:nth-child(5):nth-last-child(4), TABLE[id='summaryBasicData'] > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(8) + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(7) + TD:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(6) + TD:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(5) + TD:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(4)"}, {"Column6", "TABLE[id='summaryBasicData'] > * > TR > TH[colspan=""1""][rowspan=""1""]:nth-child(1):nth-last-child(8) + TH[colspan=""1""][rowspan=""1""]:nth-child(2):nth-last-child(7) + TH[colspan=""1""][rowspan=""1""]:nth-child(3):nth-last-child(6) + TH[colspan=""1""][rowspan=""1""]:nth-child(4):nth-last-child(5) + TH[colspan=""1""][rowspan=""1""]:nth-child(5):nth-last-child(4) + TH[colspan=""1""][rowspan=""1""]:nth-child(6):nth-last-child(3), TABLE[id='summaryBasicData'] > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(8) + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(7) + TD:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(6) + TD:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(5) + TD:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(4) + TD:not([colspan]):not([rowspan]):nth-child(6):nth-last-child(3)"}, {"Column7", "TABLE[id='summaryBasicData'] > * > TR > TH[colspan=""1""][rowspan=""1""]:nth-child(1):nth-last-child(8) + TH[colspan=""1""][rowspan=""1""]:nth-child(2):nth-last-child(7) + TH[colspan=""1""][rowspan=""1""]:nth-child(3):nth-last-child(6) + TH[colspan=""1""][rowspan=""1""]:nth-child(4):nth-last-child(5) + TH[colspan=""1""][rowspan=""1""]:nth-child(5):nth-last-child(4) + TH[colspan=""1""][rowspan=""1""]:nth-child(6):nth-last-child(3) + TH[colspan=""1""][rowspan=""1""]:nth-child(7):nth-last-child(2), TABLE[id='summaryBasicData'] > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(8) + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(7) + TD:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(6) + TD:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(5) + TD:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(4) + TD:not([colspan]):not([rowspan]):nth-child(6):nth-last-child(3) + TD:not([colspan]):not([rowspan]):nth-child(7):nth-last-child(2)"}, {"Column8", "TABLE[id='summaryBasicData'] > * > TR > TH[colspan=""1""][rowspan=""1""]:nth-child(1):nth-last-child(8) + TH[colspan=""1""][rowspan=""1""]:nth-child(2):nth-last-child(7) + TH[colspan=""1""][rowspan=""1""]:nth-child(3):nth-last-child(6) + TH[colspan=""1""][rowspan=""1""]:nth-child(4):nth-last-child(5) + TH[colspan=""1""][rowspan=""1""]:nth-child(5):nth-last-child(4) + TH[colspan=""1""][rowspan=""1""]:nth-child(6):nth-last-child(3) + TH[colspan=""1""][rowspan=""1""]:nth-child(7):nth-last-child(2) + TH[colspan=""1""][rowspan=""1""]:nth-child(8):nth-last-child(1), TABLE[id='summaryBasicData'] > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(8) + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(7) + TD:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(6) + TD:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(5) + TD:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(4) + TD:not([colspan]):not([rowspan]):nth-child(6):nth-last-child(3) + TD:not([colspan]):not([rowspan]):nth-child(7):nth-last-child(2) + TD:not([colspan]):not([rowspan]):nth-child(8):nth-last-child(1)"}}, [RowSelector="TABLE[id='summaryBasicData'] > * > TR"]),
    #"Tanıtılan Üst Bilgiler" = Table.PromoteHeaders(#"Html'den Ayıklanan Tablo", [PromoteAllScalars=true]),
    #"Değiştirilen Tür" = Table.TransformColumnTypes(#"Tanıtılan Üst Bilgiler",{{"Kod", type text}, {"Hisse Adı", type text}, {"Sektör", type text}, {"Kapanış(TL)", type number}, {"Piyasa Değeri(mn TL)", type number}, {"Piyasa Değeri(mn $)", type number}, {"Halka AçıklıkOranı (%)", type number}, {"Sermaye(mn TL)", type number}}),
    #"Kaldırılan Sütunlar" = Table.RemoveColumns(#"Değiştirilen Tür",{"Hisse Adı", "Sektör", "Kapanış(TL)", "Piyasa Değeri(mn TL)", "Piyasa Değeri(mn $)", "Halka AçıklıkOranı (%)", "Sermaye(mn TL)"}),
    #"Özel İşlev Çağrıldı" = Table.AddColumn(#"Kaldırılan Sütunlar", "Fiyat Fonksiyon", each #"Fiyat Fonksiyon (2)"([Kod])),
    #"Genişletilen Fiyat Fonksiyon" = Table.ExpandTableColumn(#"Özel İşlev Çağrıldı", "Fiyat Fonksiyon", {"Column1.HGDG_TARIH", "Column1.HGDG_KAPANIS", "Column1.DOLAR_BAZLI_FIYAT", "Column1.HGDG_HACIM"}, {"Fiyat Fonksiyon.Column1.HGDG_TARIH", "Fiyat Fonksiyon.Column1.HGDG_KAPANIS", "Fiyat Fonksiyon.Column1.DOLAR_BAZLI_FIYAT", "Fiyat Fonksiyon.Column1.HGDG_HACIM"}),
    #"Değiştirilen Tür1" = Table.TransformColumnTypes(#"Genişletilen Fiyat Fonksiyon",{{"Fiyat Fonksiyon.Column1.HGDG_TARIH", type date}}),
    #"Yeniden Adlandırılan Sütunlar" = Table.RenameColumns(#"Değiştirilen Tür1",{{"Fiyat Fonksiyon.Column1.HGDG_KAPANIS", "Fiyat(TL)"}, {"Fiyat Fonksiyon.Column1.DOLAR_BAZLI_FIYAT", "Fiyat (USD)"}, {"Fiyat Fonksiyon.Column1.HGDG_HACIM", "Hacim"}}),
    #"Değiştirilen Tür2" = Table.TransformColumnTypes(#"Yeniden Adlandırılan Sütunlar",{{"Hacim", Currency.Type}}),
    #"Yeniden Adlandırılan Sütunlar1" = Table.RenameColumns(#"Değiştirilen Tür2",{{"Fiyat Fonksiyon.Column1.HGDG_TARIH", "Tarih"}}),
    #"Değiştirilen Tür3" = Table.TransformColumnTypes(#"Yeniden Adlandırılan Sütunlar1",{{"Fiyat(TL)", Currency.Type}, {"Fiyat (USD)", Currency.Type}}),
    #"Filtrelenen Satırlar" = Table.SelectRows(#"Değiştirilen Tür3", each true)
in
    #"Filtrelenen Satırlar"
  •     #"Özel İşlev Çağrıldı" = Table.AddColumn(#"Kaldırılan Sütunlar", "Fiyat Fonksiyon", each try #"Fiyat Fonksiyon (2)"([Kod]) otherwise #table({"Column1.HGDG_TARIH", "Column1.HGDG_KAPANIS", "Column1.DOLAR_BAZLI_FIYAT", "Column1.HGDG_HACIM"},{})),
    

10 Replies

  • 1. read about try ... otherwise

    2. familiarize yourself with manual status handling in Web.Contents

    3. Power Query MUST return something that looks like a table. Add a blank table to your query flow as a placeholder.

    • lbendlin's avatar
      lbendlin
      Super User
          #"Özel İşlev Çağrıldı" = Table.AddColumn(#"Kaldırılan Sütunlar", "Fiyat Fonksiyon", each try #"Fiyat Fonksiyon (2)"([Kod]) otherwise #table({"Column1.HGDG_TARIH", "Column1.HGDG_KAPANIS", "Column1.DOLAR_BAZLI_FIYAT", "Column1.HGDG_HACIM"},{})),
      
      • Mekist's avatar
        Mekist
        Helper III

        Hello lbendlin 

         

        Thank you for your return.
        As of now, I cannot test it since there are no companies to test it with. I will test it on January 22, 2026 and provide updates.

  • v-lgarikapat's avatar
    v-lgarikapat
    Community Support

    Hi Mekist 

    Thank you for reaching out to the Fabric Community Forum.

     

    lbendlin  Thanks for your prompt response.

     

    Mekist I wanted to follow up to check if you had a chance to review the information provided by lbendlin . If you are still facing issues, please don’t hesitate to reach out  we’ll be more than happy to assist you.

     

     

    Best Regards,

    Lakshmi.

    • Mekist's avatar
      Mekist
      Helper III

      Hello v-lgarikapat 

       

      I had the opportunity to review it, but since there are no companies without data, I cannot test it at the moment.
      I will test it on January 22, 2026.