YEARFRAC equivalent for SSRS?

I am trying to replicate the YEARFRAC feature in EXCEL into SSRS.

Here's the expression in my report, but it's not returning the same results as in Excel. I'm using DateDiff...
=ReportItems!TotalValue.Value/DateDiff("yyyy",Min(Fields!order_datefulfilledValue.Value),Max(Fields!order_datefulfilledValue.Value))

Open in new window


I believe the results would be in decimals.... the YEARFRAC in Excel basically gets the fraction of a year between two dates
teknovationAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
For the benefit of those SQL Server experts that are not familiar with the Excel function YEARFRAC, can you provide us with 'before and after' sample data of what you are trying to pull off here?

Thanks in advance.
0
teknovationAuthor Commented:
Hi Jim, please see below.

=ReportItems![b]TotalValue[/b].Value/DateDiff("yyyy",Min(Fields![b]order_datefulfilledValue[/b].Value),Max(Fields![b]order_datefulfilledValue[/b].Value))

Open in new window


Sample debug code:
21/YEARFRAC("12/20/2012","01/15/2014")

10.500 is the result using the expression above when it should be 19.636

The two dates are 12/20/2012 and 01/15/2014
The total value is: 21
0
teknovationAuthor Commented:
...anyone?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
This will probably get you the same level of accuracy as the Excel YEARFRAC
=21/(DateDiff("d",Fields!FirstDate.Value,Fields!SecondDate.Value) / 365) 

Open in new window


However many developers would propose that logic like this should be in SQL, in the stored procedure that serves up the SSRS dataset...
= 21 / DATEDIFF(FirstValue, SecondValue) / 365.0) as column_name

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
teknovationAuthor Commented:
thanks ill try it. but its for crm dynamic which is fetch xml, we dont have sql server
0
teknovationAuthor Commented:
Hi Jim, thanks so much for the formula! It was pretty darn close, the values were off by .03 but good enough, unless you have something else that can make it more accurate!
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
My guess is that it's as accurate as the Excel YEARFRAC function, and the only way to test that is to do a side-by-side comparison.  If you've already done that to get to the .03 it would be worth posting it here.
0
teknovationAuthor Commented:
=21/(DateDiff("d",Fields!FirstDate.Value,Fields!SecondDate.Value) / 365) 

Open in new window


Was able to get me this close to the YEARFRAC results which is the value to the right side.
19.556 vs 19.588

49.183 vs 49.169
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -JIm

btw Check this out, it was just published a half an hour ago
Top 10 Ways to Write Rock Star Articles
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.