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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
EHP
Frequent Visitor

How necessary are the “as <type>” variable declarations in Power Query / M-Language?

I have this code excerpt:

 

GetPlanningItemChangeMarkersData = (environmentName as text, planningItemId as number) as record =>

 

which appears to behave the same way as:

 

GetPlanningItemChangeMarkersData = (environmentName, planningItemId) =>

 

Are either of these better practice than the other? I could see an argument that it's much quicker to see what GetPlanningItemChangeMarkersData will return if I leave the "as record" declaration in there, but environmentName and planningItemId are obviously going to be text and a number, so surely I could leave them out?

 

Currently I'm going to go with

 

GetPlanningItemChangeMarkersData = (environmentName, planningItemId) as record => 

 

, but I'd love to hear the community opinions on this.

 

TIA.

1 ACCEPTED SOLUTION
mpicca13
Resolver IV
Resolver IV

Its possible that not putting "as" could lead to the column being identified as either text or whole number which will be indicated by the top of the column showing "abc/123"

This could lead to additional applied steps to be made if you have to change it specifically to text or whole number. My opinion is best practice would be to put "as" wherever a specific data type is needed.

View solution in original post

1 REPLY 1
mpicca13
Resolver IV
Resolver IV

Its possible that not putting "as" could lead to the column being identified as either text or whole number which will be indicated by the top of the column showing "abc/123"

This could lead to additional applied steps to be made if you have to change it specifically to text or whole number. My opinion is best practice would be to put "as" wherever a specific data type is needed.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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