• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Parameter in source in Power Query|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Parameter in source in Power Query|Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower QueryParameter in source in Power Query
sp_PrintTopic sp_TopicIcon
Parameter in source in Power Query
Avatar
Andrzej Lewkowicz

New Member
Members
Level 0
Forum Posts: 2
Member Since:
March 25, 2021
sp_UserOfflineSmall Offline
1
March 25, 2021 - 6:40 am
sp_Permalink sp_Print

I want to download a lot of data via API (https://fantasy.premierleague......summary/4/). Number 4 in the source is ID. ID is a number from range 1-700 and I want to download all the data. The data is in JSON format so i'm using power query to download it and translate into table. My solution was to create a table in spreadsheet with ID parameter and write a macro to go from 1 to 700 copy-pasting data to another spredsheet.

 

I successfully declared a variable from the table

let
Źródło = Excel.CurrentWorkbook(){[Name="Tabela2"]}[Content],
ID = Record.Field(Źródło{0}, "Kolumna1")
in
ID

 

And then I struggle with the query. I declared ID and included it in source (Źródło in Polish). The error I'm getting is that i can't use & for text & number. I tried to convert Par to text using number.totext or text.from but then i receive message that "Import text.from does not match any export".

Can someone help me or get any idea how to do that in other wat?

let
ID = Par,
Źródło = Json.Document(Web.Contents("https://fantasy.premierleague.com/api/element-summary/" & Par & "/")),
history = Źródło[history],
#"Przekonwertowane na tabelę" = Table.FromList(history, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Rozwinięty element Column1" = Table.ExpandRecordColumn(#"Przekonwertowane na tabelę", "Column1", {"element", "fixture", "opponent_team", "total_points", "was_home", "kickoff_time", "team_h_score", "team_a_score", "round", "minutes", "goals_scored", "assists", "clean_sheets", "goals_conceded", "own_goals", "penalties_saved", "penalties_missed", "yellow_cards", "red_cards", "saves", "bonus", "bps", "influence", "creativity", "threat", "ict_index", "value", "transfers_balance", "selected", "transfers_in", "transfers_out"}, {"Column1.element", "Column1.fixture", "Column1.opponent_team", "Column1.total_points", "Column1.was_home", "Column1.kickoff_time", "Column1.team_h_score", "Column1.team_a_score", "Column1.round", "Column1.minutes", "Column1.goals_scored", "Column1.assists", "Column1.clean_sheets", "Column1.goals_conceded", "Column1.own_goals", "Column1.penalties_saved", "Column1.penalties_missed", "Column1.yellow_cards", "Column1.red_cards", "Column1.saves", "Column1.bonus", "Column1.bps", "Column1.influence", "Column1.creativity", "Column1.threat", "Column1.ict_index", "Column1.value", "Column1.transfers_balance", "Column1.selected", "Column1.transfers_in", "Column1.transfers_out"})
in
#"Rozwinięty element Column1"

Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4449
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
2
March 25, 2021 - 8:53 am
sp_Permalink sp_Print

Hi Andrzej,

Welcome to our forum!

You haven't shown how you tried to convert the ID to text, so I can't troubleshoot what went wrong there. My suggestion is: after the source step in the ID query, set the data type for Par to text before converting to a record.

If that doesn't help, please provide a sample file, or at least sample code of what you have tried.

Mynda

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1518
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
3
March 25, 2021 - 12:42 pm
sp_Permalink sp_Print

Hi Andrzej,

You can do this by creating a list of the ID numbers 

ID_List = {1..686}

Any number over 686 caused a 404 Not Found error on the website.  

 

Then using List.Transform, call a function to get the web pages

WebPages = List.Transform(ID_List, each GetPages(_))

 

This is the GetPages function

GetPages = (ID) =>
let
Pages = Json.Document(Web.Contents("https://fantasy.premierleague.com/api/element-summary/"& Text.From(ID) & "/")),
History = Pages[history]
in History

 

The full code and about 18,000 rows of results are in the attached Excel workbook.

Regards

Phil

Avatar
Andrzej Lewkowicz

New Member
Members
Level 0
Forum Posts: 2
Member Since:
March 25, 2021
sp_UserOfflineSmall Offline
4
March 25, 2021 - 6:11 pm
sp_Permalink sp_Print

Thanks both,

@Philip - it works! and i learnt GetPages function.

I'm a bit new to power query but it seems really powerful tool.

Regards

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Nikole Roland, dan conner, Christoffer Sandberg
Guest(s) 11
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 871
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
Jessica Stewart: 204
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Brett Dryland
Saeed Aldousari
Bhuwan Devkota
Kathryn Patton
Maria Conatser
Jefferson Granemann
Glen Coulthard
Nikki Fox
Rachele Dickie
Raj Mattoo
Forum Stats:
Groups: 3
Forums: 24
Topics: 6222
Posts: 27291

 

Member Stats:
Guest Posters: 49
Members: 31912
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.