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
Nietzsche
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
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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