Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

Need to pass the variables dynamically into sql script as a source into Power BI Desktop

Hi Team,

I have a script which has the date variable mentioning as below image which are highlighted . If I pull this script into Power BI Desktop(SQL Source-Query) How can I pass the values into this variable from Power BI Desktop using the filter Slicer. Please do the needful asap as I have ambiguity on this .Thank You so Much.

 

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Team,

    This is the simple exampel to understood

    Declare @Employee varchar(max)

    Set @Employee = 'Filter Value from Slicer Visual from Power BI'

    Select top 10
    EmployeeID,EmployeeAddress from Employee where EmployeeName=@Employee

    If we select Employee = 'Dhoni' from Power BI Slicer Visual , the sql source script should as follows


    Declare @Employee varchar(max)

    Set @Employee = 'Dhoni'

    Select top 10
    EmployeeID,EmployeeAddress from Employee where EmployeeName='Dhoni'

    If we pass multiple values like Employee = Dhoni,Kohli then the sql query should be as follows 

    Declare @Employee varchar(max)

    Set @Employee = 'Dhoni','Kohli'

    Select top 10
    EmployeeID,EmployeeAddress from Employee where EmployeeName in ('Dhoni','Kohli')

    Please do the needful . Thank You.




    • Anonymous's avatar
      Anonymous
      Not applicable

      I have seen this from different source and its posted in 2016 . I hope any chances that can available now

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    Please take a look at the following link to see if it helps, and hopefully some other expert in Power BI will be able to solve it.

     

    How-do-I-pass-parameters-to-my-SQL-statement 

     

    Hope it helps,


    Community Support Team _ Caitlyn

    If this post helps then please consider Accept it as the solution to help the other members find it more quickly.