如何在字符串中找到一年?

发布于 2025-02-09 19:38:21 字数 464 浏览 1 评论 0原文

我尝试编写一个自定义功能,该功能将在给定的字符串中找到当前或明年的当前功能。假设我在name列中有一个字符串:a2022_new_accruals.xlsx。如果不是,我需要返回1,如果不是,则null。我写了此功能,但它给了我错误:

= if Text.Contains([Name], Date.ToText(Date.Year(DateTime.LocalNow()),"yyyy")) or Text.Contains([Name], Date.ToText(Date.AddYears(Date.Year(DateTime.LocalNow()),1),"yyyy")) then 1 else null

错误:

expression.error:无法将函数类型的值转换为日期类型

I try to write a custom function which is going to find a current or next year in a given string. Let's say I have a string in a Name column: A2022_new_accruals.xlsx. I need to return 1 if it's true, null if it's not. I wrote this function but it gives me error:

= if Text.Contains([Name], Date.ToText(Date.Year(DateTime.LocalNow()),"yyyy")) or Text.Contains([Name], Date.ToText(Date.AddYears(Date.Year(DateTime.LocalNow()),1),"yyyy")) then 1 else null

Error:

Expression.Error: Cannot convert value of Function type to Date type

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走走停停 2025-02-16 19:38:21

尝试

let Source = #table({"Name"},{{"A2021_new_accruals.xlsx"},{"A2022_new_accruals.xlsx"},{"A2023_new_accruals.xlsx"},{"A2024_new_accruals.xlsx"}}),
ThisYear=Date.Year(DateTime.LocalNow()),
#"Added Custom" = Table.AddColumn(Source, "Custom", each if Text.Contains([Name],Text.From(ThisYear)) or Text.Contains([Name],Text.From(ThisYear+1)) then 1 else null)
in #"Added Custom"

try

let Source = #table({"Name"},{{"A2021_new_accruals.xlsx"},{"A2022_new_accruals.xlsx"},{"A2023_new_accruals.xlsx"},{"A2024_new_accruals.xlsx"}}),
ThisYear=Date.Year(DateTime.LocalNow()),
#"Added Custom" = Table.AddColumn(Source, "Custom", each if Text.Contains([Name],Text.From(ThisYear)) or Text.Contains([Name],Text.From(ThisYear+1)) then 1 else null)
in #"Added Custom"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文