英文:
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
= 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.
英文:
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.
答案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])
英文:
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])
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论