Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
steambucky
Helper III
Helper III

DATEDIFF syntax error in measure.

Hello I am doing some wrong here....

 

Power BI Desktop error.png

 

All i am trying to do create a measure that calculates the months since animals have been vacinated.

 

This is the what i am writing:

 

Since vac = DATEDIFF(NOW(),(VacDate),Month)

 

I tried this as well but it doesnt like that either....any ideas?

 

Since vac = DATEDIFF(NOW(),(Sheet1[VacDate]),Month)

 

The message I get is: A single value for column 'VacDate' in table 'Sheet1' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

 

The data type of VacDate is date and and I am confused the calc is using DATEDIFF....

 

 

Marc.

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

 

Does this work?

 

=DATEDIFF(MAX(Data[VacDate]),TODAY(),Month)


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

 

Does this work?

 

=DATEDIFF(MAX(Data[VacDate]),TODAY(),Month)


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hello Ashish,

 

Your suggestion DID work with some small modifications. Thank you for your time.

 

I am curious about the following -  This is what finally worked.

 

(My new Measure)  Since last Vac = DATEDIFF(MAX(Sheet1[VacDate]),TODAY(),Month)

 

This also worked in a new column:

 

(New Column) Since last Vac = DATEDIFF([VacDate],NOW(),Month)

 

But the same but if swap that code between the column and measure is doesnt work. Any idea why?  

 

 

You are welcome.  In a calculated column formula, [VacDate] picks up the value in the current row of that column column.  In a measure, when you mention [VacDate], it refer to all entries in that column.  To get it to refer to the current row, we use the MAX function.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Greg_Deckler
Super User
Super User

If VacDate is a column, then you need to wrap it in an aggregator like MAX or MIN. If it is a measure, then [VacDate]. 

 

Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.