Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Created By: Alex Powers
- YouTube How To Video: https://www.youtube.com/watch?v=LwIod7Dm46s
- Website: http://www.itsnotaboutthecell.com
- Contact: [email protected]
- LinkedIn: https://www.linkedin.com/in/alexmpowers/
- Instructions: Create Two Seperate Functions in Power Query M
- */
- /* Return Total Number of Pages - Base 0 */
- (produceType as text) as number =>
- let
- Source = Web.Page(Web.Contents("https://ndb.nal.usda.gov/ndb/search/list?qlookup=" & produceType)),
- Data1 = Source{1}[Data],
- Children = Data1{0}[Children],
- Children1 = Children{1}[Children],
- Children2 = Children1{1}[Children],
- Children3 = Children2{1}[Children],
- Children4 = Children3{0}[Children],
- Children5 = Children4{10}[Children],
- #"Removed Other Columns" = Table.SelectColumns(Children5,{"Children"}),
- #"Expanded Children" = Table.ExpandTableColumn(#"Removed Other Columns", "Children", {"Text"}, {"Text"}),
- #"Changed Type" = Table.TransformColumnTypes(#"Expanded Children",{{"Text", Int8.Type}}),
- #"Removed Errors" = Table.RemoveRowsWithErrors(#"Changed Type", {"Text"}),
- MaxCount = List.Max(Table.Column(#"Removed Errors", "Text")) - 1
- in
- MaxCount
- /* Return Table */
- (produceName as text, pageOffset as number) as table =>
- let
- Source = Web.Page(Web.Contents("https://ndb.nal.usda.gov/ndb/search/list?qlookup=" & produceName & "&offset=" & Text.From(pageOffset) & "&order=asc")),
- Data0 = Source{0}[Data],
- #"Removed Columns" = Table.RemoveColumns(Data0,{""})
- in
- #"Removed Columns"
Advertisement
Add Comment
Please, Sign In to add comment