15

I’m creating a calculated column in a Power BI report. The calculated column concatenates integer and text columns. I tried using the below query to accomplish this, but it resulted in a syntax error.

CalculatedColumn = Number.ToText(table1.[RegionID]) & " " &  table1.[RegionName]

I tried some other conversion methods also, which were not successful. Could someone please guide me on how one could achieve the above objective in Power BI?

Matt Kocak
  • 736
  • 2
  • 6
  • 25
bmsqldev
  • 2,627
  • 10
  • 31
  • 65
  • 3
    Why do you need to convert at all? You should be able to do: `= table1.[RegionID] & " " & table1.[RegionName]` – John Kurlak Jun 24 '16 at 14:39

6 Answers6

19

Try

= "Text" & Number.ToText(Number)
DreamTeK
  • 32,537
  • 27
  • 112
  • 171
Rafael Loureiro
  • 191
  • 1
  • 2
10

You must use the function format. The first argument is the value itself, and the second one is the format you want. Use "string", like the code below:

=FORMAT([RegionID], "string") & " " & [RegionName]
Daniel Labbe
  • 1,979
  • 3
  • 15
  • 20
10

Make sure you have the correct format string.

Try this:

= FORMAT(table1.[RegionID], "#") & " " & table1.[RegionName]

Unheilig
  • 16,196
  • 193
  • 68
  • 98
ziviland
  • 124
  • 1
  • 4
4

=FORMAT(numeric_value, string_format) recognises nine formats for the second argument of =FORMAT(), where the type of string format is specified. The 0tri0g error referred to above arises because string itself isn't one of the nine formats. You can see the full list here: https://msdn.microsoft.com/query-bi/dax/pre-defined-numeric-formats-for-the-format-function.

In the original case here, you'd use =FORMAT([Year], "General Number"] to return a year as a four-digit number, stored as text.

amunnelly
  • 1,144
  • 13
  • 22
0

I have created the calculated column as below without any explicit conversion:

Region = table1.[RegionID] + " " + table1.[RegionName]
bmsqldev
  • 2,627
  • 10
  • 31
  • 65
0

You can use the FORMAT keyword as stated the the above comments.

Just make sure if concatenating strings, use the '&' not '+'. If you still get errors, use format.

Region = FORMAT(table1.[RegionID], "#") & " " & table1.[RegionName]

You can use "string" instead of "#" too.

Coffee and Code
  • 885
  • 14
  • 16