SQL 如何在 Power BI 中将整数转换为文本值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38010256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:40:56  来源:igfitidea点击:

how to convert a Integer to Text value in Power BI

sqlpowerbidaxm

提问by bmsqldev

I am creating a calculated columnin existing power BI report. the calculated columnconcatenates integer& textcolumns. I tried below query which give syntax error to me,

我正在创建一个calculated column现有的power BI report. 在calculated column符连接integertext列。我尝试了下面的查询,它给了我语法错误,

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

I tried some other conversion methods which were not a success. Someone please guide me how to achieve the above scenario in power bi

我尝试了其他一些不成功的转换方法。有人请指导我如何在power bi中实现上述场景

采纳答案by ziviland

Make sure you have the correct format string.

确保您有正确的格式字符串。

Try this:

尝试这个:

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

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

回答by Rafael Loureiro

Try

尝试

= "Text" & Number.ToText(Number)

回答by Daniel Labbe

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]

回答by amunnelly

=FORMAT(numeric_value, string_format)recognises nine formats for the second argument of =FORMAT(), where the type of string format is specified. The 0tri0gerror referred to above arises because stringitself 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.

=FORMAT(numeric_value, string_format)识别 的第二个参数的九种格式=FORMAT(),其中指定了字符串格式的类型。出现上面提到的0tri0g错误是因为string它本身不是九种格式之一。您可以在此处查看完整列表: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.

在此处的原始情况下,您将使用=FORMAT([Year], "General Number"]以四位数形式返回年份,并以文本形式存储。

回答by Wing

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

您可以使用 FORMAT 关键字,如上述注释所述。

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.

您也可以使用“字符串”代替“#”。

回答by bmsqldev

I have created the calculated columnas below without any explicitconversion:

我创建了calculated column如下,没有任何explicitconversion

Region = table1.[RegionID] + " " + table1.[RegionName]