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
Anonymous
Not applicable

Minor Formatting Query- Why Always put a space before parenthesis ‘(‘ and ‘)’

SQLBI DaxFormatter suggests to always put a space before parenthesis ‘(‘ and ‘)’.

Why is it recommended? I do understand it makes the code more readable but when the intellisense suggests any function- and we select the suggested function, PBI by default does not introduce a space before opening parenthesis.

It shows as CALCULATE( 
Not CALCULATE (
To manually introduce space is counter-productive, what are your thoughts? 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@Anonymous yes by default it doesn't give the space and I'm in such a habit that I always do it manually. Think thru this, it doesn't auto-format like put things on the next line, you still have to do that to make the expression more readable, so adding space for the bracket is not too much off work since I have to manually format my DAX expression, line breaks, etc. Doing it for so long, so many hours, it is just natural now. I wish there is an inbuilt DAX formatter.

 

Not sure what else to say? At end of the day, it is for my own convenience and preference, sometimes my DAX expression is very very long, and it helps me to understand it clearly when I go back and look at it. I found that little effort to manually format pays off when you are writing complex expressions.

 

Just my 2 cents.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

12 REPLIES 12
parry2k
Super User
Super User

Thanks for sharing @Anonymous 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

@parry2k @daxer-almighty Sharing what I heard from Marco below

Gguliani_0-1624842133026.png

 

parry2k
Super User
Super User

@Anonymous I'm very confident they will come back. Looking forward to their input. Well done!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@Anonymous no idea, I guess that is the question you need to ask the developers. I format the code the way I want regardless of what these formatting tools do for me. I wish I have a better answer.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Thanks @parry2k - Really appreciate it, am more informed if not sorted.

I have reached out to Marco/ Alberto from SQL BI to see if they can answer why it behaves the way it does. Would let you know if i hear from them. It could be because of this formatting rule that they have on their site- "Write a function inline only if it has a single argument that is not a function call"

parry2k
Super User
Super User

@Anonymous yes TE is Tabular Editor.

 

I know it has two formatting options, short line (ctrl + f6) and long line (f6), if you use a short line, it will break it into different lines.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

@parry2k I discovered that too- however, wanted to why long line is default for both TE & daxformatter.com and even it is the standard they have, how does it decide which codes to show in short lines and which in long lines even if by default- it still is long line in settings. I hope I am not confusing you.

 

Basically, for many codes that I go to check formatting- it shows results with indentation (despite the setting been Long Line, I never change it). But in some cases, like the formula shared above- it doesn't show the answer with indenting. Wanted to know why it behaves, the way it does- the rationale.

Anonymous
Not applicable

@parry2k I believe you are referring to Tabular Editor.

This really helped me- thanks

One last thing- would you know why my indented multi-line code got converted to a single line by TE?

DIVIDE ( [Total Baked], CALCULATE ( [Total Baked], ALL () ) )

Why is that in some cases (like the one above) formulas are restricted to a single line while, in most cases, they still shown up in multi-line codes. What's the logic that derives which approach to use when by DAX formatters?

parry2k
Super User
Super User

@Anonymous and one more thing, now I'm using more and more TE, it has a formatter that takes care of a lot of the stuff.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@Anonymous yes by default it doesn't give the space and I'm in such a habit that I always do it manually. Think thru this, it doesn't auto-format like put things on the next line, you still have to do that to make the expression more readable, so adding space for the bracket is not too much off work since I have to manually format my DAX expression, line breaks, etc. Doing it for so long, so many hours, it is just natural now. I wish there is an inbuilt DAX formatter.

 

Not sure what else to say? At end of the day, it is for my own convenience and preference, sometimes my DAX expression is very very long, and it helps me to understand it clearly when I go back and look at it. I found that little effort to manually format pays off when you are writing complex expressions.

 

Just my 2 cents.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

@parry2k Thanks for your response. The issue I face with it is that when I select a function that Intellisense suggests as I am typing- the function by default comes up with no space between the function and opening parenthesis.

Do you then manually introduce a space everytime- Isn't it inefficient? Or is there a way to avoid manual intervention?

parry2k
Super User
Super User

@Anonymous I always use space, it is a personal preference. Here is example of my DAX code:

 

Count of Customers in Segment = 
VAR __Table = 
ADDCOLUMNS ( 
    VALUES ( Sheet1[Customer_Id] ), 
    "@Relevant Order", [Relevant order] 
)
RETURN
COUNTX ( 
    CROSSJOIN ( Segment, __Table ),  
    IF ( [@Relevant Order] >= [Min] && [@Relevant Order] <= [Max], 
        1 
    ) 
)

 

It is easy to read and follow when you come back in the future. In fact, I also add the comments, which I will do in the above measure as well.

 

Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.