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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
mdgene
Helper I
Helper I

Using Column name as a variable

Hi Please I am trying to pass column name as a variable to create a table.

 

This query is fine (Ii am using the column name explicitly)

TestTable =
var b =
CALCULATETABLE(
SELECTCOLUMNS('Hours Table',
"test",'Hours Table'[Hours]),
FILTER('Hours Table','Hours Table'[Team] = "a")
)
return
b
 
This query returns no row and no error
TestTable2 =
var t = "'Hours Table'[Team]"
var b =
CALCULATETABLE(
SELECTCOLUMNS('Hours Table',
"test",'Hours Table'[Hours]),
FILTER('Hours Table',t = "b")
)
return
b
 
Please any idea why the variable is not recognised in the filter context
1 ACCEPTED SOLUTION
v-angzheng-msft
Community Support
Community Support

Hi, @mdgene 

Because in the following formula, the variable T is not recognized as a column in the table, but as a text. You cannot label a column in the variable way above.
Therefore, in the filter function, the filtering condition is that text 1 is equal to text 2, not that the column value is equal to "b", so the result of the filter function is empty, and the returned table is empty.

vangzhengmsft_0-1647826656812.png

vangzhengmsft_1-1647826705694.png

 

 

Best Regards,
Community Support Team _ Zeon Zheng


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

View solution in original post

3 REPLIES 3
mdgene
Helper I
Helper I

Thanks for the update

Hi, @mdgene 

Is the above post helpful to you?

If  it does, could you please mark the post which help as Answered? It will help the others in the community find the solution easily if they face the same problem with you. Thank you.😀


Best Regards,
Community Support Team _ Zeon Zheng


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

v-angzheng-msft
Community Support
Community Support

Hi, @mdgene 

Because in the following formula, the variable T is not recognized as a column in the table, but as a text. You cannot label a column in the variable way above.
Therefore, in the filter function, the filtering condition is that text 1 is equal to text 2, not that the column value is equal to "b", so the result of the filter function is empty, and the returned table is empty.

vangzhengmsft_0-1647826656812.png

vangzhengmsft_1-1647826705694.png

 

 

Best Regards,
Community Support Team _ Zeon Zheng


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

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.