Strings and single quotes

When programming in DAX you can use both double quotes ” and single quotes ‘ to contain strings. You must use double quotes when using labels, but aside from that, functionally they work the same.

One consideration is the best practices. Personally I use compile level 4, which will flag up unused variables and lots of useful information to keep your code clean, but it also flags up strings that are not labels. This is often a problem with data migration scripts as you will often use strings, but wont want to create DAX labels for them. You also don’t want the best practice engine from flagging them up, so the best course of action is to use single quotes to contain the strings as this will not cause a best practice warning.

If when using single quotes and you want to include a single quote within the string, you need to ensure you use \’ where you want the single quote, as this will be interrupted as a single quote within a string.

Advertisements

One thought on “Strings and single quotes

  1. The rule can be expressed as 2 cases:
    Texts addressed to humans- use double quotes : ” and convert these to labels
    Texts which have machine meaning – use single quotes. Interface constants or SQL queries would be good example.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s