Power Query 抛出:“我们无法将运算符 & 应用于文本和数字类型。”如何将参数连接到 M 代码中? [已关闭]

问题描述 投票:0回答:2

参数

TestID
已定义,并且严格来说是一个数值。

但是无论我嵌入它,Power Query 都会抛出错误:

我们无法将运算符

&
应用于文本和数字类型。
详情:
运算符=
&

TestID = Excel.CurrentWorkbook() {[Name="TestID"]}[Content]{0}[Column1]

select ...   
where  
time@timestamp  
between  
(select distinct max([time@timestamp]) from [POD01EVENTLOG] where [data_format_4] = 1 and [data_format_0] = "&TestID&")  
and  
(select distinct max([time@timestamp]) + 60 from [POD01EVENTLOG] where [data_format_4] = 1 and [data_format_0] = "&TestID&")

我的 Power Query M 代码是:

let 
    TestID = Excel.CurrentWorkbook() {[Name="TestID"]}[Content]{0}[Column1],
    Source = Sql.Database("SERVERNAME", "DBNAME", 
    [Query="



SELECT *

from [POD01RAWDATA]

where 
time@timestamp 
between 
(select distinct max([time@timestamp]) from [POD01EVENTLOG] where [data_format_4] = 1 and [data_format_0] = "&TestID&")
and 
(select distinct max([time@timestamp]) + 60 from [POD01EVENTLOG] where [data_format_4] = 1 and [data_format_0] = "&TestID&")



"])

in
    Source
type-conversion concatenation parameter-passing powerquery m
2个回答
1
投票

您无法连接数字和文本,因此在连接之前将 testid 转换为 TEXT

" & Number.ToText(TestID,"D") & "

1
投票

或者做

&Text.From(TestID)&
© www.soinside.com 2019 - 2024. All rights reserved.