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
lguelcher
Regular Visitor

If won, then calculate difference between two dates

I'm trying to add a calculated column to calculate the number of days between two dates. However, I need to only calculate for those that meet a certain criteria. 

 

The formula I tried is: 

DiffCloseDate = if(Opportunities[Status]="won",(Opportunities[Actual Close Date]-Opportunities[Est Close Date]),"")

 

For the 'then' clause, I also tried

Datediff(Opportunities[Est Clsoe Date],Opportunities[Actual Close Date],Days)

 

 

The error I'm receiving is:

A single value for column 'Actual Close Date' in table Opportunities 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.

 

But, I don't want to aggregate the dates. I just want each row to perform the calculation.

 

Thanks for any help.

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Are you sure that you are using a calculated column because the error you are getting is for a measure. If you use a calculated column, your formula would generate an error regarding "variant" data because you are trying to return a number and a string at the same time. Both have to agree in terms of the data type returned. So, you could do something like this as a calculated column (not a measure)

 

DiffCloseDate = IF(Opportunities[Status]="won",Opportunities[Actual Close Date]-Opportunities[Est Close Date],-999)

@ 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...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

Are you sure that you are using a calculated column because the error you are getting is for a measure. If you use a calculated column, your formula would generate an error regarding "variant" data because you are trying to return a number and a string at the same time. Both have to agree in terms of the data type returned. So, you could do something like this as a calculated column (not a measure)

 

DiffCloseDate = IF(Opportunities[Status]="won",Opportunities[Actual Close Date]-Opportunities[Est Close Date],-999)

@ 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...

@lguelcher, are you defining this column in the 'Opportunities' table?

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.

Top Solution Authors
Top Kudoed Authors