Search code examples
apipowerbipowerbi-datasourcepower-bi-report-server

How to set selected value from slicer to API in PowerBi


I want to select the time from the slicer and put the user-selected value into API. After I get the value from API and analysis will be going on my local machine and set the analyzed data into PowerBi(for user-selected data).

enter image description here

I set the above slicer using the following API.

http://localhost:9002/ANC/analysis/parameterList

Python file :

from flask import Flask, jsonify, abort,request
import time
app = Flask(__name__)

@app.route('/ANC/analysis/parameterList',methods=['GET'],endpoint='parameterList')
def parameters():
    data = {
            "time":["lastMonth","lastYear","lastWeek","lastHour","lastDay"],
           
            }
    return data

if __name__ == '__main__':
    app.run(debug=True,host='0.0.0.0',port=9002)


# url6 = 'http://localhost:9002/ANC/analysis/parameterList'

Is it possible to get the user-selected parameter into local analysis via API PowerBi? Or is there any way to solve this?


Solution

  • PowerBI does not work like a web development framework. You cannot "post" the selection in a slicer to an API.

    I can think some options that could give an acceptable alternative:

    1. You import all the data from the API endpoint. Then use the slicer to slice as designed. For large amounts of data (in the API) there are techniques for paging that data in to PowerBI using M. Here is an example. PowerBI will handled gigabytes of data with ease although the API might not be up to the task.

    2. Use an intermediate database / datamart / datawarehouse to model the data and run your PowerBI on top of the datastore. With this approach you can use DirectQuery to limit the data you process through to PowerBI.

    3. If you are working locally and only using PowerBI desktop. You can set parameters in your PowerBI file and then supply the time through the parameters. If you save your PowerBI file as a PowerBI template (PBIT), then it saves your PowerBI without any data. When you open the template it will prompt you to supply the parameters.

    Not quite a 100% answer but I hope it gives you some options to consider.