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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
BenBlackswan
Helper V
Helper V

Is there a better place to define this variable?

Hi everyone,

 

I am looking at a code where variable countryOfBirth is defined inside an argument inside SELECTCOLUMNS which itself is inside another variable.

 

I wonder if this is the appropciate place to define such variable? Can it be defined outside the SELECTCOLUMNS statement?

Nietzsche_0-1723078549954.png

 

thank you.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Nietzsche,

 

You can use the FORMAT(INT(RELATED(dimCountry[Code])), "0000") expression directly for later judgment instead of using a variable to store its return value.

vdengllimsft_0-1723102464702.png

 

But this makes the code very difficult to read and maintain.

If you declare a variable externally and then reassign a value to that variable, you cannot use the RETURN expression later.

vdengllimsft_1-1723102477685.png

 

Or declare the complete variable directly externally. However, this will not recognize the columns in the /dimCountry/ table.

vdengllimsft_2-1723102491871.png

 

Therefore, in general, this approach of yours to declaring variables is appropriate.


Best Regards,

Dengliang Li

 

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

2 REPLIES 2
Anonymous
Not applicable

Hi @Nietzsche,

 

You can use the FORMAT(INT(RELATED(dimCountry[Code])), "0000") expression directly for later judgment instead of using a variable to store its return value.

vdengllimsft_0-1723102464702.png

 

But this makes the code very difficult to read and maintain.

If you declare a variable externally and then reassign a value to that variable, you cannot use the RETURN expression later.

vdengllimsft_1-1723102477685.png

 

Or declare the complete variable directly externally. However, this will not recognize the columns in the /dimCountry/ table.

vdengllimsft_2-1723102491871.png

 

Therefore, in general, this approach of yours to declaring variables is appropriate.


Best Regards,

Dengliang Li

 

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

Thank you very much for the detailed explanation.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.