You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Power Query M函数报无法将Function转Text错误,求错误定位

M (Power Query) 函数错误排查与修正

核心错误点

  • 错误1:误用each关键字生成了函数类型变量:M语言中each是匿名函数的语法糖,代码中txtCheckInEvent = each lstCheckinTimeLst、txtCheckOutEvent = each lstCheckOutTimeLst两行将两个变量定义成了函数类型,后续传入DateTime.FromText时触发「无法将Function类型转换为Text类型」的报错。
  • 错误2:未对列表元素逐批处理:Text.Split返回的是文本列表,DateTime.FromText只能接收单个文本值,不能直接传入整个列表做转换,也无法直接对两个列表做批量减法运算。
  • 错误3:文本拼接逻辑错误:Duration.ToText只能对单个时长值做转换,直接传入时长列表会报错,需要先遍历列表将所有时长转为文本后,再调用Text.Combine拼接。

修正后的代码

let 
    Source = (txtCheckInTime as text, txtCheckOutTime as text) as text =>
        let
            // 拆分时间序列为列表
            lstCheckinTimeLst = Text.Split(txtCheckInTime, ", "),
            lstCheckOutTimeLst = Text.Split(txtCheckOutTime, ", "),
            // 配对两个列表的逐对元素,转换为时间后计算时长
            EventDurationList = List.Transform(
                List.Zip({lstCheckinTimeLst, lstCheckOutTimeLst}),
                (pair) => DateTime.FromText(pair{0}) - DateTime.FromText(pair{1})
            ),
            // 批量转换为文本后拼接
            Result = Text.Combine(List.Transform(EventDurationList, Duration.ToText), ", ")
        in
            Result
in
    Source

运行效果

使用提供的输入示例运行,返回结果为:00:00:05, 00:00:05, 00:00:04

内容的提问来源于stack exchange,提问作者Abdelrahman.fathy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.23 18:54:01