to 函数报错 "to 步长错误"

 

问题描述

报表使用 to 函数动态扩展,例如 =to(1,ds1.count(),2)等类似写法,访问报错:“表达式:to(1,ds1.count(),2) 中: to 步长错误”,遇到这种情况应该如何排查?

解决方案

我们先将 to 函数表达式拆分执行 ds1.count()表达式发现结果为 0,因此 to(1,0,2) 函数用法错误,我们可以通过 if 函数进行一次判断,if(ds1.count()==0,1,ds1.count())。
最终我们 to 函数的表达式写法为:=to(1,if(ds1.count()==0,1,ds1.count()),2)。