Forum Discussion

Walt101062's avatar
Walt101062
New Member
1 year ago
Solved

Creating a Report froma source with an API connect

I have a connection from Power BI to a data source via an API. Noob question: I would like the user to be able to select the period for the report. I'm not sure what date range the API allows, and ...
  • v-pnaroju-msft's avatar
    1 year ago

    Thankyou, DataNinja777, for your response.

    Hi Walt101062,

    We appreciate your question posted on the Microsoft Fabric Community Forum.

    As per my understanding, since the API requires From and To dates, Power BI lets users enter the dates, which we can then use in the API request by creating Parameters in Power BI Desktop.

    Please follow the steps below to resolve the issue:

    1. In Power BI Desktop, go to Manage Parameters and create two parameters named StartDate (type: Date) and EndDate (type: Date).
    2. Modify the API URL in Power Query and include these parameters in the API URL as shown in the example.

      let

          StartDateText = Date.ToText(StartDate, "yyyy-MM-dd"),

          EndDateText = Date.ToText(EndDate, "yyyy-MM-dd"),

          Source = Json.Document(Web.Contents("https://your-api-endpoint.com/data?",

              [Query = [from = StartDateText, to = EndDateText]]

          ))

      in

          Source

    3. Change the parameter values before refresh. In Power BI Desktop, you can update these values directly. In Power BI Service, go to Dataset, then Settings, and then Parameters to update and refresh.

    Additionally, please refer to the following links for more information:
    Parameters - Power Query | Microsoft Learn
    Web.Contents - PowerQuery M | Microsoft Learn

    If you find our response useful, kindly mark it as the accepted solution and give kudos. This will help other community members who have similar questions.

    If you have any further queries, please feel free to contact the Microsoft Fabric community.

    Thank you.