Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
CoffeeAddict
Yak Posting Veteran
94 Posts |
Posted - 2012-06-28 : 01:32:11
|
I'm totally new to doing calculations in T-SQL. I guess I'm wondering what is a weighted average and how do you do it in T-SQL for a field?Here's an example of a calculated field I have after calling one of our UDFs. Now this has to be a weighted average also...no idea where to start to turn this into a weighted average.So ultimately this UDF I call from my view, after I pass in some values returns a calculated value Set @AverageCostG = ((@AvgFullYear_Rent * @Months) + (@PrevYearRent * @PrevYearMonths)) / @Termso in my view I'm calling the UDF above to get back that @AverageCostG CREATE View MyTestView AS select v.*, --TODO: get rid of *, that's just for testing, select actual field names CalculateAvgRentG(d.GrossNet, d.BaseMonthlyRent, d.ILI, d.Increase, d.Term) as AverageRent_G, .... from SomeOtherView vNow I need to I guess make this AverageRent_G a weighted average somehow...I'm sorry I'm not a BI Developer but I'm on a stupid BI project. Just need a bit of help the first time through this.Do I need to know WHAT they want weighted or is it assumed that hey, it's obvious.. I do not know what I need to know in order to do the weighted average for these guys...like what specs I need if any from them other than this calculation I've created based off the UDF call. I mean do I have to do some crazy select join or something in addition to multiplying 2 fields and dividing by something to average it? How do I know what fields they are to be used int he weighted average and from where? I admit I'm totally new and lost to this. |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
|
|