How do I create a Power Query function that dynamically adjusts based on input parameters

0 votes

How do I create a Power Query function that dynamically adjusts based on input parameters?
I need a Power Query function that modifies its transformations based on input parameters. How can I design a dynamic function that adapts its behavior based on user-defined inputs to ensure flexibility and reusability?

Mar 13 in Power BI by Evanjalin
• 25,690 points
77 views

1 answer to this question.

0 votes

If you want to build a Power Query function that can dynamically respond to input parameters, you must define a function that takes parameters to modify its transformation logic conditionally. Other approaches are given as follows:

1. Very Basic Dynamic Function for Filtering Data

You could build a function that filters a table according to some chosen column and value defined by the user:

(SourceTable as table, ColumnName as text, FilterValue as any) =>  
let  
    FilteredTable = Table.SelectRows(SourceTable, each Record.Field(_, ColumnName) = FilterValue)  
in  
    FilteredTable  

 FilteredTable  
Usage: DynamicFilter(Data, "Category", "Electronics") will return only rows where the "Category" column is "Electronics."


2. Function to Select Specific Columns Dynamically
This function allows users to choose which columns to keep:

(SourceTable as table, ColumnsToKeep as list) =>  
let  
    SelectedColumns = Table.SelectColumns(SourceTable, ColumnsToKeep, MissingField.Ignore)  
in  
    SelectedColumns  

Usage:

SelectColumnsDynamic(Data, {"Product", "Sales"}) will return only the "Product" and "Sales" columns.

3. Dynamic Transformation Function Based on User Inputs

This function allows users to apply different transformations (e.g., changing case, replacing values) dynamically

(SourceTable as table, ColumnName as text, Operation as text) =>  
let  
    TransformedTable =  
        if Operation = "Uppercase" then  
            Table.TransformColumns(SourceTable, {{ColumnName, Text.Upper}})  
        else if Operation = "Lowercase" then  
            Table.TransformColumns(SourceTable, {{ColumnName, Text.Lower}})  
        else  
            SourceTable  
in  
    TransformedTable  

Usage:

DynamicTransform(Data, "CustomerName", "Uppercase") converts all values in "CustomerName" to uppercase.

answered Mar 13 by anonymous
• 25,690 points

Related Questions In Power BI

0 votes
0 answers
0 votes
2 answers

How do I create a Power BI visual that dynamically adjusts based on user-selected filters and slicers?

The application of slicers and filters in ...READ MORE

answered Jan 23 in Power BI by anonymous
• 22,890 points
176 views
0 votes
1 answer

How can I create a Power BI heatmap that dynamically adjusts based on filters?

Filters can dynamically affect the Power BI ...READ MORE

answered 5 days ago in Power BI by anonymous
• 25,690 points
37 views
0 votes
1 answer

How can I create a multi-row card that dynamically adjusts based on the number of selected values?

To create a multi-row card in Power ...READ MORE

answered Mar 18 in Power BI by anonymous
• 25,690 points
71 views
0 votes
1 answer

Install Power BI Desktop

It’s a pretty simple process. All you ...READ MORE

answered Oct 9, 2018 in Power BI by Kalgi
• 52,350 points
1,231 views
0 votes
1 answer

Few tips before I start creating Power BI dashboard

It’s always advisable to begin with the data ...READ MORE

answered Oct 9, 2018 in Power BI by Kalgi
• 52,350 points
1,046 views
0 votes
1 answer

How do I format the KPI in Power BI

format the KPI by selecting the paint ...READ MORE

answered Oct 9, 2018 in Power BI by Kalgi
• 52,350 points
1,400 views
+1 vote
1 answer
0 votes
1 answer

How can I create a function in Power Query that processes data differently based on a user-selected parameter?

The following steps outline the creation of ...READ MORE

answered Mar 17 in Power BI by anonymous
• 25,690 points
96 views
0 votes
1 answer

How do I create a dynamic column in Power Query that calculates based on multiple conditions?

To create a dynamic column in Power ...READ MORE

answered 5 days ago in Power BI by anonymous
• 25,690 points
40 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP