Power Query - 将整数转换为自定义列中的文本
Power Query - Converting whole number to text in a CUSTOM COLUMN
在 power 查询中添加新列时,我需要将 3 个整数列转换为公式中的文本。我知道如何使用 FORMAT 函数在 dax 中执行此操作,但我无法使其在 power 查询中工作。
3 columns are - click to veiw
下面是我的自定义栏目:
= Table.AddColumn(RefNo.3, "Refernce Number", each
if Text.Length([RefNo.3]) > 1 and Text.Length([RefNo.3]) < 11 then [RefNo.3]
else if Text.Length([RefNo.2]) > 1 and Text.Length([RefNo.2]) < 11 then [RefNo.2]
else if Text.Length([RefNo.1]) > 1 and Text.Length([RefNo.1]) < 11 then [RefNo.1]
else null)
但是,目前我收到此错误:
Expression.Error:我们无法将 Table 类型的值转换为 Number 类型。
细节:
值=[Table]
类型=[类型]
所以我知道我需要先在公式中将整数列转换为文本。此外,我之前必须有意将这 3 列从文本转换为整数,以去除多余的值(因此我无法将其还原)。提前谢谢大家。
有多种方法可以解决这个问题,具体取决于您的真实数据。
- 只需在执行
AddColumn
函数之前将列设置为 Type.Text
。
- 如果这样做,您还必须检查 null,因为它们会导致您编写的脚本失败
- 或者您可以在测试之前用另一行用空字符串 ("") 替换空值:
Table.ReplaceValue(table_name,null,"",Replacer.ReplaceValue,{"RefNo", "RefNo2", "RefNo3"})
,
- 如果都是正整数,比较值而不是字符串长度:例如
>=0 and <10000000000
- 构造一个数值数组,return最后一个通过过滤器的值
= Table.AddColumn(your_table_name, "Reference Number",
each List.Accumulate(List.Reverse(List.RemoveNulls({[RefNo],[RefNo2],[RefNo3]})),
null,(state,current)=> if state = null then
let
x = Text.Length(Text.From(current))
in
if x > 1 and x < 11 then current else state
else state))
在 power 查询中添加新列时,我需要将 3 个整数列转换为公式中的文本。我知道如何使用 FORMAT 函数在 dax 中执行此操作,但我无法使其在 power 查询中工作。
3 columns are - click to veiw
下面是我的自定义栏目:
= Table.AddColumn(RefNo.3, "Refernce Number", each
if Text.Length([RefNo.3]) > 1 and Text.Length([RefNo.3]) < 11 then [RefNo.3]
else if Text.Length([RefNo.2]) > 1 and Text.Length([RefNo.2]) < 11 then [RefNo.2]
else if Text.Length([RefNo.1]) > 1 and Text.Length([RefNo.1]) < 11 then [RefNo.1]
else null)
但是,目前我收到此错误: Expression.Error:我们无法将 Table 类型的值转换为 Number 类型。 细节: 值=[Table] 类型=[类型]
所以我知道我需要先在公式中将整数列转换为文本。此外,我之前必须有意将这 3 列从文本转换为整数,以去除多余的值(因此我无法将其还原)。提前谢谢大家。
有多种方法可以解决这个问题,具体取决于您的真实数据。
- 只需在执行
AddColumn
函数之前将列设置为Type.Text
。- 如果这样做,您还必须检查 null,因为它们会导致您编写的脚本失败
- 或者您可以在测试之前用另一行用空字符串 ("") 替换空值:
Table.ReplaceValue(table_name,null,"",Replacer.ReplaceValue,{"RefNo", "RefNo2", "RefNo3"})
,
- 如果都是正整数,比较值而不是字符串长度:例如
>=0 and <10000000000
- 构造一个数值数组,return最后一个通过过滤器的值
= Table.AddColumn(your_table_name, "Reference Number",
each List.Accumulate(List.Reverse(List.RemoveNulls({[RefNo],[RefNo2],[RefNo3]})),
null,(state,current)=> if state = null then
let
x = Text.Length(Text.From(current))
in
if x > 1 and x < 11 then current else state
else state))