电源查询function可选参数

我怎样才能创build一个可选参数pls的权力查询function? 我尝试过创build函数语法的各种排列,目前是这样的:

let fnDateToFileNameString=(inFileName as text, inDate as date, optional inDateFormat as nullable text) => let nullCheckedDateFormat = Text.Replace(inDateFormat, null, ""), value = if nullCheckedDateFormat = "" then inFileName else Text.Replace(inFileName, inDateFormat, Date.ToText(inDate, inDateFormat )) in value in fnDateToFileNameString 

我将它传递给一个testing,如下所示:

  = fnDateToFileNameString("XXXXXXXXXXXXXXXXXX", #date(2015, 3, 21), null) 

这抛出:

 "An error occurred in the fnDateToFileNameString" query. Expression.Error: we cannot convert the value null to type Text. Details: Value= Type=Type 

问题是在Text.Replace中,因为第二个参数不能为空:在文本值中replace字符null是没有意义的。 如果将nullCheckedDateFormat更改为以下nullCheckedDateFormat = if inDateFormat = null then "" else inDateFormat,该函数将起作用: nullCheckedDateFormat = if inDateFormat = null then "" else inDateFormat,

这在下一步中有点多余,所以你可以像这样重写函数:

 let fnDateToFileNameString=(inFileName as text, inDate as date, optional inDateFormat as nullable text) => if inDateFormat = null or inDateFormat = "" then inFileName else Text.Replace(inFileName, inDateFormat, Date.ToText(inDate, inDateFormat )) in fnDateToFileNameString