有没有办法将 PowerBI/Power Query 中日期数据类型列中的空值转换为空白?

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

我正在将组合的 SharePoint 列表利用到 Power BI 中的单个合并表中。与各种疾病的休息日期相关的三列是:[TestDate1]、[TestDate2]、[TestDate3]。

我在自定义列中有这个逻辑:

if [TestDate1] <= [TestDate2] then [TestDate1] else if [TestDate1] <= [TestDate3] then [TestDate1] else if [TestDate2] <= [TestDate1] then [TestDate2] else if [TestDate2] <= [TestDate3] then [TestDate2] else if [TestDate3] <= [TestDate1] then [TestDate3] else if [TestDate3] <= [TestDate2] then [TestDate3] else "" 

但是,所有 TestDate 均为 null。这导致列中出现错误,因为空值不能在 PowerQuery 中的逻辑函数中使用(根据我的理解),所以有没有办法可以测试这个逻辑以查看它是否会产生预期的结果?

谢谢!

null powerbi powerquery
2个回答
0
投票

您可以显式测试公式中的空值,例如

= if [TestDate1] = null then XXX else YYY

但你最好的选择可能是将整个事情包装在 try .. otherwise 以防返回错误

= try if a then b else c otherwise ZZZ

对于您的代码:

= try if [TestDate1] <= [TestDate2] then [TestDate1] else if [TestDate1] <= [TestDate3] then [TestDate1] else if [TestDate2] <= [TestDate1] then [TestDate2] else if [TestDate2] <= [TestDate3] then [TestDate2] else if [TestDate3] <= [TestDate1] then [TestDate3] else if [TestDate3] <= [TestDate2] then [TestDate3] else "" otherwise ZZZZ

其中 ZZZ 是您想要返回的内容(例如 null 或 [TestDate1] 或“”)而不是返回错误


0
投票

我对这个问题的担忧是,最好保留“null”而不是单元格中的“空白”/空值。

用 null 替换空白值可确保数据表示的一致性,从而更轻松地处理和分析数据。此外,“空”值被识别为缺失数据,使您能够应用适当的数据分析技术和可视化。

什么方法可以促进 Power BI 中使用“null”或“blank”之间的精确计算?

还有什么替代方案?

© www.soinside.com 2019 - 2024. All rights reserved.