1

我有一列包含从业务系统下载的价格,并且根据国家/地区的不同,这些数字具有不同的格式,例如:

1.260,14 -> this is seen as text by Excel
1,280.14 -> this is seen as text by Excel
1280.14  -> this is the only correct one, seen as number

我希望 Power Query 将所有内容都转换为数字,在这种情况下,这意味着所有 3 个数字都应该是:“1280.14”

4

4 回答 4

1

如果您知道哪些文件来自哪个国家/地区,您还可以在使用Table.TransformColumnTypes. 您可以右键单击该列并选择更改类型 | 使用区域设置... 这将生成类似Table.TransformColumnTypes(Step, {{"Column Name", Currency.Type}}, "locale name").

于 2016-03-18T18:45:02.563 回答
1

1)在小数位拆分列:按字符数拆分列:2 - 尽可能向右一次

2)第一栏:替换“。” 由“”(无)

3)第一列:用“”替换“,”(无)

4)用“。”合并两列。作为分隔符并更改为十进制格式

于 2016-03-18T14:36:44.233 回答
0

这是我刚刚将混合格式文本转换为数字的 Power Query 函数。它将最后一次出现的点或逗号视为小数分隔符,只要该字符在文本中仅出现一次。

要使用此功能,请转到“Power Query”功能区选项卡,单击“From Other Sources”>“Blank Query”。然后转到“高级编辑器”并将下面的脚本复制粘贴到编辑器并保存。然后,您可以返回主查询并单击“添加列”>“添加自定义列”。“=”之后的公式是:toNumber([column name])

let

     toNumber = (text) =>

let

//remove characters that occur more than once as they can't be decimal separators
       text1 = if List.Count(Text.PositionOf(text, ",", Occurrence.All)) > 1
         then Text.Replace(text, ",", "") else text
,      text2 = if List.Count(Text.PositionOf(text1, ".", Occurrence.All)) > 1
         then Text.Replace(text1, ".", "") else text1

//if there are still more than one potential decimal separator, remove the kind that occurs first
//let's assume the last one is the actual decimal separator
,      text3 = if List.Count(Text.PositionOfAny(text2, {",","."}, Occurrence.All)) > 1
         then Text.Replace(text2, Text.At(text2, Text.PositionOfAny(text2, {",","."}, Occurrence.First)), "") 
         else text2

//cast as number (try different decimal separators)
,      number = 
  try       Number.ToText(Number.From(Text.Replace(text3,",","."))) 
  otherwise Number.ToText(Number.From(Text.Replace(text3,".",","))) 

in

      number
in
    toNumber
于 2016-07-26T12:03:51.283 回答
0

您可以通过以下方式确定小数:

Text.Middle(Number.ToText(1 / 2), 1, 1)

Number.ToText(1 / 2)是字符串“0.5”或“0,5”,具体取决于您使用的任何未知语言环境。Text.Middle将返回该字符串的第二个字符。

于 2021-10-12T22:15:20.827 回答