如何在 Excel 的 PowerQuery 中将整数转换为字符串

How do you cast an integer to a string in Excel's PowerQuery

我有一个可以返回两列的 PowerQuery;一个 Number (整数),另一个 Text (字符串)。 我想创建一个连接这些的自定义列。

这似乎应该有效:="(" & ([Value] as text) & ", " & [Description] & ")"

但是这个returns错误Expression.Error: We cannot convert the value 1 to type Text.

注意:此问题与 PowerQuery 编辑器(即 M 语言)有关;不是常规的 Excel 工作表函数。实现我所追求的工作表函数是 =concatenate("(", A2, ", ", B2, ")"),其中 A2 是值,B2 是描述。

使用Number.ToText(n)函数。

="(" & Number.ToText([Value]) & ", " & [Description] & ")"

https://msdn.microsoft.com/en-us/library/mt253385.aspx?f=255&MSPPError=-2147217396

使用Text.From(s)。它还支持非数字类型。如果您不确定输入的类型(例如:用户定义的单元格),它会很有用。

Returns the text representation of a number, date, time, datetime, datetimezone, logical, duration or binary value. If a value is null, Text.From returns null.

https://msdn.microsoft.com/en-us/library/mt253343.aspx