Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
AJose
Helper I
Helper I

I have a parameter which decides which column to select from a table. If the parametet value is "A",

I have a parameter which decides which column to select from a table. If the parametet value is "A", "Column1" should e selected and if the parametet value is "B", "Column2" should e selected . Can I do this with Table.SelectColumns in M code?

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @AJose 

What do you mean by "which column to select from a table"?

Does it mean selecting different columns from table to used in a visual or to used in a formula(measure/calculated column)?

Could you show more details?

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Let me explain the the problem in detail. I am loading data from SharePoint List to Power BI and trying to create a Power BI template. I have defined certain parameters in Power BI using 'Manage Parameters' feature. I need to select the columns from the datasource based on the parameter values . I am using Table.SelectColumns (M Query) to select columns. Is there a way that I can use 

1. if statement in Table.SelectColumns like if Parameter value  = "A" then column1 else column2.  or

2. call a custom function in Table.SelectColumns which will retrun the column name based on the parameter value

 

 

Hi @AJose 

It is possible to use parameter to select data from data source.

Passing parameters to queries in Power Query

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.