Forum Discussion

Koritala's avatar
Koritala
Post Patron
8 months ago

Need Help in Passing Dynamic parameters in main dataset

Hi All,

Can anyone share the sample code to pass the parameters dynamically into main dataset(where report use the table).

My source is redshift views and I have a prompts on different dimensions. I want to apply the prompts filters dynamically before loading the data into power bi report builder so that we can get the good performance.

I am failing at pass the parameters in the main dataset code. I have searched many sources. But could not get the proper syntax to include the parameters in the main dataset code.

Appriciate if anyone can respond asap as it is urgent.

Thans,

Sri

 

19 Replies

  • Here are two common, working patterns.

     

    1) Single value

    SELECT *
    FROM your_view
    WHERE region = region

     

    2) Multi-value parameter

    Redshift won’t accept IN (@Param) unless the driver expands it correctly, so the safest approach is to pass a single string and split it in SQL.

    In Report Builder:

    • Create parameter pRegion (Allow multiple values)

    • Create a second hidden parameter pRegionCsv with default:
      =Join(Parameters!pRegion.Value, ',')

    SELECT *
    FROM your_view
    WHERE (
      @pRegionCsv = 'ALL'
      OR region IN (
        SELECT TRIM(value)
        FROM SPLIT_TO_TABLE(@pRegionCsv, ',')
      )
    )

     

    This pushes filtering to Redshift before the report renders, which is what you want for performance.

     

    If your parameters are numeric IDs, remove quotes and cast value to INT.

     

    • Koritala's avatar
      Koritala
      Post Patron

      Hi cengizhanarslan,

      I couldn't understand the hidden parameter. 

      Can you please share the sample report file for my better understanding?

      Appriciate your help.

      Thanks,

      Sri

  • Hi Koritala 

     

    Please check this and confirm

     

    Create Parameters in Dataset
    sql
    In Dataset Properties → Parameters tab
    Add parameters like:
    @StartDate (Date)
    @EndDate (Date)
    @Department (Text)
    @Region (Text)

     

    Use in SQL Query
    SELECT *
    FROM your_redshift_view
    WHERE
    -- Date parameters
    (@StartDate IS NULL OR date_column >= @StartDate)
    AND (@EndDate IS NULL OR date_column <= @EndDate)
    -- Text parameters
    AND (@Department IS NULL OR department = @Department)
    AND (@Region IS NULL OR region = @Region)
    -- Multi-select parameters (comma-separated)
    AND (@ProductList IS NULL OR product_id IN (
    SELECT value FROM STRING_SPLIT(@ProductList, ',')
    ))

     
  • Koritala 

    Since you mentioned your data source is Amazon Redshift, I am assuming you are using "Get Data" experience in Paginated reports. 

    If yes then I would suggest you to first 

    1. Connect to Redshift with the Power Query editor using the "Get Data" experience in paginated reports.

    2. Create a table by pulling the data from redshift view

    3. Create a m parameter (to apply filter on your view) with some default value

    4. Filter the table you created in step 2 using the parameter you created in step 3

     

    Then load the data into Paginated report builder.

    Then in Report builder,

    1. create a parameter

    2. Bind the parameter to the table, steps are here: https://learn.microsoft.com/en-us/power-bi/paginated-reports/report-builder/connect-snowflake-databricks-power-query-online#how-to-bind-parameters

     

    This way, you will be able to achive the desired output.

    Also, there is a great video from Guy in a Cube channel, where they explained all the steps 

    https://www.youtube.com/watch?v=OQKgnJkjJDI

    I followed these steps in my reports and it is working fine.

    Hope this helps

     

     

     

     

    Connect on LinkedIn

     

     

     








    Did I answer your question? Mark my post as a solution!
    If I helped you, click on the Thumbs Up to give Kudos.

    Proud to be a Super User!


  • v-hjannapu's avatar
    v-hjannapu
    Community Support

    Hi Koritala,

    I would also take a moment to thank krishnakanth240, for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.
     

    I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.

    Regards,
    Community Support Team.

    • v-hjannapu's avatar
      v-hjannapu
      Community Support

      Hi Koritala,
      I hope the above details help you fix the issue. If you still have any questions or need more help, feel free to reach out. We are always here to support you.


      Regards,
      Community Support Team.

    • Koritala's avatar
      Koritala
      Post Patron

      Hi v-hjannapu,

      I followed the krishna's steps and not able to get the result.

      for everyone reference, here I am attaching error screenshots.

       

      Thanks,

      Sri

      • v-hjannapu's avatar
        v-hjannapu
        Community Support

        Hi Koritala,

        Thanks for sharing the screenshots.

        The problem is happening only because of multi-value parameter selection with Amazon Redshift.

        In Report Builder, when you select multiple values, it sends them to the dataset as a single comma-separated value example: North, South. Redshift does not support using this directly in the IN condition like SQL Server. Because of this, the dataset query fails and the report preview shows errors.

        That is the reason Single value selection is working, Multiple value selection is failing

        This is a limitation with Redshift + Paginated Reports, not an issue with your report design.

        To handle this, the filtering needs to be done either inside the Redshift view itself, or by splitting the values using Redshift-supported functions, or by building the query dynamically in the dataset expression. There is no direct out-of-box support for multi-value parameters with Redshift in Report Builder.

        Hope this explains the behavior clearly. Let us know if you want help with any workaround.

        Regards,
        Community Support Team.