在“自定义列”中使用“DateDiff”函数。

huangapple go评论80阅读模式
英文:

Use 'DateDiff' function in a 'Custom Column'

问题

I am trying to create a custom column in PowerBI which calculates the number of days between Date column and today. So I follow the example from

and do = Table.AddColumn(#"Grouped Rows", "Custom", each DateDiff([Date], Today(), Day)). But I get an error saying Expression.Error: The name 'DateDiff' wasn't recognized. Make sure it's spelled correctly. My guess is I can't use DAX function in the 'Custom column formula`. But when I look at the available formula from the popup. I can't find one which calculates the number of days between 2 columns. 在“自定义列”中使用“DateDiff”函数。

英文:

I am trying to create a custom column in PowerBI which calculates the number of days between Date column and today. So I follow the example from https://www.enjoysharepoint.com/power-bi-date-difference/#:~:text=To%20find%20the%20difference%20between%20the%20date%20from,measure%20%3ADiff%20%3D%20DATEDIFF%20%28Table1%20%5BDate%5D%2C%20TODAY%20%28%29%2CDAY%29 and do

= Table.AddColumn(#"Grouped Rows", "Custom", each DateDiff([Date], Today(), Day))

But I get error saying Expression.Error: The name 'DateDiff' wasn't recognized. Make sure it's spelled correctly

My guess is I can't use DAX function in the 'Custom column formula` . But when I look at the available formula from the popup. I can't find one which calculates the number of days between 2 columns.
在“自定义列”中使用“DateDiff”函数。

答案1

得分: 0

Duration.Days(Date.From(DateTime.LocalNow())-Date.From([日期列]))

英文:

It looks like you are in PowerQuery.

Duration.Days(Date.From(DateTime.LocalNow())-Date.From([Date Column]))

答案2

得分: 0

No, you can't use DAX. Power Query uses M formula language. There you can use Duration to calculate a duration, and more specific Duration.Days in your case. Get the current date and time using for example DateTimeZone.UtcNow (working with UTC is recommended to avoid some unexpected results when publishing your report to the service for example) and convert that to a date using DateTime.Date. So the code for the custom column could be something like this:

Duration.Days(DateTime.Date(DateTimeZone.UtcNow()) - [Date])

在“自定义列”中使用“DateDiff”函数。

英文:

No, you can't use DAX. Power Query uses M formula language. There you can use Duration to calculate a duration, and more specific Duration.Days in your case. Get the current date and time using for example DateTimeZone.UtcNow (working with UTC is recommended to avoid some unexpected results when publishing your report to the service for example) and convert that to a date using DateTime.Date. So the code for the custom column could be something like this:

Duration.Days(DateTime.Date(DateTimeZone.UtcNow()) - [Date])

在“自定义列”中使用“DateDiff”函数。

huangapple
  • 本文由 发表于 2023年5月20日 14:18:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76293786.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定