Hi
I'm fairly new to power query and I don't understand exactly how I'm suppose to solve this.
So i have a query to takes out data for each month from Azure Billing API Rest web service and creating a table that I then use in excel later on.
The Query works just fine but it's "static" meening that I have to add the query manually for each month and i can't do the whole year since then it fails.
So i would like to find a way to do a loop on month level and in that loop i need to get a value that I can then use in my query so i can get a dataset that i can "add" to my table.
That way it would be possible for me to use that power query table the whole year without haveing to update it each month.
Is this possible?
This is the structure of my query currently:
let
Data1 =
let
Source = Json.Document(Web.Contents("https://management.azure.com/providers/Microsoft.Billing/billingAccounts/.../invoices?api-version=20...periodEndDate=2021-02-01&periodStartDate=2022-01-01")),
<doing some more stuff>
in
#"MyDatatable",
Data2 =
let
Source = Json.Document(Web.Contents("https://management.azure.com/providers/Microsoft.Billing/billingAccounts/.../invoices?api-version=20...periodEndDate=2021-03-01&periodStartDate=2022-02-01")),
<doing some more stuff>
in
#"MyDatatable",
Data3 =
...
DataTable = Table.Combine({Data2,Data3,Data4,Data5,Data6,Data7,Data8,Data9})
in
DataTable
My aim is to just have ONE query that I can use in a loop "for each month from year start to current month", and in that loop the periodEndDate and periodStartDate values change depending on where in the loop I am and then adding that data to a the "DataTable".
That way i don't need to add the a query when we get to a new month...
the 2 problems i have in this is that i don't know how i should do the loop and get the date to "change" and how I add the data in my query to the data table that will be returned in the end (the "DataTable") in each loop.
Any help is appriciated
Best Regards
Ronny
Solved! Go to Solution.
Hello @Ronny75 ,
you can create a table with columns for start- and end-date and then one row for each page.
Then add a column to this table that calls a function doing the extraction. When expanding that column you'll receive one table with all your data consolidated.
I've described the general method here: Web Scraping 2: Scrape multiple pages at once and refresh in Power BI service – The BIccountant
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Hello @Ronny75 ,
you can create a table with columns for start- and end-date and then one row for each page.
Then add a column to this table that calls a function doing the extraction. When expanding that column you'll receive one table with all your data consolidated.
I've described the general method here: Web Scraping 2: Scrape multiple pages at once and refresh in Power BI service – The BIccountant
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Thanks alot for that.
Had some problems first, since my parameters where Date and not Text i had to choose to get "Column name" instead of Date when i did the "Invoke Custom Function" in my Months Table but when i found that it worked like a charm.
Very nice solution, thanks for the help!