Forum Discussion
Api call dynamic date determine by the user
Hello,
I don't know if this is possible in PowerBi but I would like generate an API call based on the selected period in my "Calendar" filter.
If the selected period changes, the API call should refresh (either automatically or manually by clicking "Refresh").
In PowerQuery mode, my API works.
My question is: how do I retrieve the selected period so that I can pass the start_date and end_date values to my API call?
Example: By default the first call is made over a period from "01/01/2023" to "11/07/2023". So I have a table of data based on this period.
If the user changes the calendar period for example from "01/04/2023" to "11/07/2023", the API call would need to update and only cover this period.
If you have a solution to solve this problem it will be very appreciaded.
Thank you so much,
4 Replies
- cpwebb
Microsoft Employee
In theory yes, it might be possible - in practice no, you aren't going to be able to do this in any useable way. In order to do what you're describing here you'd need to have a DirectQuery dataset where the source is your REST API and that's what Power BI doesn't support: https://blog.crossjoin.co.uk/2021/04/25/can-i-build-a-power-bi-directquery-dataset-on-top-of-a-rest-api/
Where does your REST API get its data from? The best thing to do is create an Import mode dataset to load all the data you need from that source. If that's not possible you could use your REST API as the source for the Import mode dataset, making as many calls as you need to load all the data that might ever need to be displayed in a report.
- Quentin_
Helper I
Hello cpwebb
Thank you for your reply.
I must have a table based on the selection calendar because if I request all my API I will have data day by day.
Exemple :Date visits Bounce rate 01/01/2023 1000 0,5 02/01/2023 5000 0,3 ... ... ... 11/07/2023 1300 0,4
It's not a problem if I create a measure to calculate "visits" column but my calcul will be wrong if I apply a measure on bounce rate column because the result of API is already an average. If I create a measure I will apply an average to another average :s
It's the reason why I must refresh my api call based on the user selection period.Thank you 🙂
- cpwebb
Microsoft Employee
OK, well as I said you won't be able to do this with Power BI - your only option will be to get the raw data and recreate all the calculations in a measure.