Analysis :: Median Calculation Using MDX

May 28, 2015

 I have a fact table fct_line_details having two columns mtid, productivity

  mtid     productivity
  1           400
1           200
1          600
2          700
3         900

I want to calculate the median for each mtid in SSAS . (median for mtid 1=400 )

View 2 Replies


ADVERTISEMENT

Median Calculation Wrong

Mar 4, 2008



I used the Median() function in a calculated measure in a cube. All seemed well until one of my users, a statistician, pointed out that the displayed values were incorrect. I investigated this and finally built the simplest cube with three records and the displayed median does not make sense, i.e. equal what a median value should be.

The 3 records have loan amounts as a measure with these values: $102,500, $168,400, and $172,181 and loan number keys of 1, 2, and 3. That's it.

The median should be $168,400 since the number of items is odd and that is the middle value.

But the cube calculated measure displays $170,290.50. It appears to be taking the average of the middle row and the next value.

When I increase the number of records I get the same odd behavior but it not only alternates (of course) with odd and even (since they use different formulats for odd and even) but the odd wrong results alternate within themselves. The apparent calculations for 5 or 7 records are different compared to 3, 9, 11, 13, 15, 17 records. The first set seems to be calculating odd number of items median by averaging the middle value + the value BEFORE the middle value while the second set of odd rows (3, 9, etc) seem to be calculating median by averaging the middle value + the value AFTER the middel value. The even numbers result in the larger of the two middle values being selected instead of the average (financial median) or the lower number (as one poster claimed for statistical median).

My calculated measure MDX is very simple:


MEDIAN( [Test Fact].[Loan Number].Members, [Measures].[Loan Amount])

Ideas anyone? Am I missing something? Is this a bug?

Thanks!

- Grant

View 6 Replies View Related

Transact SQL :: Multiple Columns Needs Median Calculation

Oct 27, 2015

I need to get the median for the 10 columns in my table. For the sake of example, I've reduced it to 2 columns. 

The code below works perfectly if i compute for only 1 column and certainly doesn't for multiple columns.

Is there a way to better handle the median computation in one pass, if multiple columns are involved?

DECLARE @tbl as table (id_n int, col1 int, col2 int)
insert into @tbl
values (1, 1, 2), (1,3, 4), (1, 5, 7), (2, 4, 7), (2, 7, 7), (2, 3, 5), (2,5, 5), (3, 1, 2), (3, 3, 5), (3, NULL,11)
select *
from @tbl
order by id_n, col1

[Code] .....

View 6 Replies View Related

Analysis :: SSAS Calculation With Division Combined With A Time Calculation?

Sep 17, 2015

I have created calcalated measures in a SQL Server 2012 SSAS multi dimensional model by creating empty measures in the cube and use scope statements to fill the calculation.

(so I can use measure security on calculations

as explained here  )

SCOPE [Measures].[C];

THIS = IIF([B]=0,0,[Measures].[A]/[Measures].[B]);

View 2 Replies View Related

Analysis :: Calculating A Rolling Median Over A Period Of 3 Years?

Jun 17, 2015

calculating a rolling median over a period of 3 years.

I already calculate median and I've tried to calculate rolling median over a period of 3 years as below.

 MEDIAN([Date].[Year].CurrentMember.Lag(3):[Date].[Year].CurrentMember,[Measures].[median])

What this does is, it calculates the median of the medians over the period of 3 years. But, what I'm looking for is the overall median of the underlying measure over a period of 3 years.

What I have now:

Year1 - 41,52,73;  Median1 - 52
Year2 - 6,9,12;  Median2- 9
Year3 - 24,68,89; Median3 - 68
Overall Median of 9,52,68 - 52

What I need:

Year1 - 41,52,73;  Median1 - 52
Year2 - 6,9,12;  Median2- 9
Year3 - 24,68,89; Median3 - 68

Overall Median of 41,52,73,6,9,12,24,68,89 is 41 

View 4 Replies View Related

Analysis :: Calculation On Row Level / If Value Is Above Or Less Than Average

Aug 3, 2015

I have a set of data and calculated already the average of a specific measure, incl. the Standarddeviation of this measure. Now I want to create a average measure of the values on row level which arehigher than [Avg]-[StdDev] AND lower of [Avg]+[StDev].As far as I understand I have to check on Rowlevel, which means on Date and Brand Level, if the value of the measure is above or lower than the Mean +/- StdDev.

SUM( FILTER( {[Dim 1].[Attribue].&[selected]},[Measures].[Fact Survey Count] > [Measures].[Mean + 0,5 StDev] AND [Measures].[Fact Survey Count] < [Measures].[Mean - 0,5 StDev] ),[Measures].[Fact Survey Count])

which leads to a wrong result. This one counts all rows if true.With Descendants I got a #Value-Error, probably because I did not understand how the calculations work. I planned to include this in a IIF calculation.

SUM( Descendants(
    {[Dim 1].[Attribute].&[selected],
    [Dim Date].[Date].[Date].CURRENTMEMBER}, Leaves), [Measures].[Fact Survey Count])

View 4 Replies View Related

Analysis :: Calculation Based On Dimension Value

Oct 8, 2015

Need to resolve this calculation, which I would believe is something very common on SSAS environments. 

Like many companies, my company has different ways of calculating Sales and the two I want to focus are Sales Gross and Sales Net. 

At a high level, we calculate Sales Gross as Sales with returns, and Sales Net as Sales without returns.

We have an attribute called Order Type that has various types of orders a user can execute with my company. One of them is Returns. If you return something back to us, we record that as a return line on the sales table. With that, we can calculate that return, breaking data down by Order Type, such as:

Order Type Line Total

Mail Orders $ 776,655.44

Internet Orders $ 2,211,334.00

Call Center Orders $ 11,223,344.00

Credit Orders  $ (55,666.00)

Today, to calculate Sales Gross and Sales Net, we are creating two dimensions: DimSalesGross and DimSalesNet. 

To calculate Sales Gross, we leave the data at the natural state, not making any changes to mappings. 

To calculate Sales Net, we map Credit Orders to Call Center Orders at the ETL level, getting a Net value for sales (Orders - Returns), however, I doubt this is the correct way of doing. 

I would like to have a Line Total Net / Line Total Gross calculation, which would be based on the Order Type value.

Perhaps using a CASE statement in MDX? Is the above possible?

View 4 Replies View Related

Analysis :: Calculation That Excludes Filters

Jul 8, 2015

I'm trying to calculate the average number of sick days per person so that it can be broken down by person role or department or some other dimension. I have a calculation for sick days that works ok and is [measures].[sick days.I'm trying to create another calculation that is [total staff] but it doesn't work.

My final calculation will be [avg sick days] =  [measures].[sick days] / [measures].[total staff]

The bit I can't get to work is making it ignore any filters. For example I have a measure called [staff] and as you would expect it can be broken down by [person].[role] or [department].[department].

I'm trying to get [total staff] to return the total when it's used with [person] or [department]. I've managed to get it to work with [person] by using ROOT([Person]) but then I will need to do this for all different hierarchies that will use it.

View 12 Replies View Related

Mdx/analysis/reporting Service For Date Calculation

Apr 8, 2008

Hi,

I have a cube with the following
DimStartDate
DimEndDate
DimArea
FactDataCount

I need to output the following report

Area 5days 10days 30days
Miami 4 2 1
Memphis 3 3 2

1)Where do I do the dateDiff calculation, at report or cube level?
2)How do I work out which dates belong to the above groups? I'm assuming i have to check if the dateDiff lies between those numbers?

thanks

View 2 Replies View Related

Analysis :: Display Calculation For Structure And Attributes Only

Jun 29, 2015

I have a calculation that granularity is on a specific level and therefore would like the calculation to be only visible/calculate when with a specific dimension structure & attributes

SCOPE([Measures].[Complaint Rate]);
SCOPE([Item Dimension].[Item Structure].Members);
this=(IIF([Measures].[Sales Units]=0,NULL,(([Measures].[Count]/[Measures].[Sales Units])*1000000)));
END SCOPE;
END SCOPE;

This displays the calculation all the time even if no item attributes are selected, I only want the calculation applicable to the structure & attributes belonging to structure - I tried children, currentmember etc. but no luck - its probably something small I am missing. Tried this too

this=(IIF([Measures].[Sales Units]=0,NULL,(([Item Dimension].[Item Structure].CURRENTMEMBER,[Measures].[Count]/[Item Dimension].[Item Structure].CURRENTMEMBER,[Measures].[Sales Units])*1000000)));

View 4 Replies View Related

Analysis :: Total Calculation With Filter For Parallel Period

Nov 30, 2015

I have developed a cube in my work place for analyzing current year sales with previous year sales in Time Hierarchy (Year- Quarter- Month) using Parallel period. If we want to see data for particular Quarters i.e. Q1 and Q2 then total at the year level should also get change. Currently if we only choose 2 quarters in the filter then current year data gets change, however data using parallel period is not getting change accordingly and its shows Total of full year.

View 4 Replies View Related

Analysis :: SSAS Tabular - Preview Of Calculation Not Working

Oct 30, 2015

Does any1 know why preview of a DAX calculation does not work? I mean once you enter the calculation in the bottom of the table it doesnt´t show up.

View 8 Replies View Related

Analysis :: YTD Calculation For Multiple Hierarchies With SCOPE Statement

Jul 2, 2015

I am stuck in a situation where I want to use YTD for three different calendars of our company and don't want to create three different YTD calculations. However I want to make this work for any measure not for a particular measure

If I create one YTD and try to use in context of three calendars in SCOPE statements then it does not give my right results. Following is my syntax but It does not work.

SCOPE([Billing Date].[SalesCalendar].MEMBERS);
( [Aggregate].[AGGREGATE CODE].[YTD] )   
          = Aggregate({[Aggregate].[AGGREGATE CODE].DefaultMember}*{PERIODSTODATE([Billing Date].[SalesCalendar].[Sales Calendar Year],[Billing Date].[SalesCalendar].CURRENTMEMBER) } );

[Code] ....

However if I comment on one of SCOPE statement , other one works but both don't work simultaneously in context of different calendars.

View 2 Replies View Related

Analysis :: Total Calculation Incorrect When Using IF In Calculated Member

Oct 27, 2015

I cannot understand why Total of calculated member is displayed incorrect. How should I change calculated member for it to work correctly?

Calculated Member:
     CREATE MEMBER CURRENTCUBE.[Measures].AverageScore
        AS IIF([Measures].[Distance]<2001,0,[Measures].[avgscore]/[Measures].[Date Count]),
     VISIBLE = 1;

It seems that Total is calculated without checking value in "AverageScore" for that month.

View 3 Replies View Related

Analysis :: MDX To Filter For Completed Periods Only (part Of Annualized Calculation)

Sep 9, 2015

I have been following the tutorial/blog post HERE to create an annualization (or "run rate") of my Gross Amount measure.  What I want to do now is exclude any period that is not "complete".  

For example, if today is 9/9 then Q3 is not complete - only Q1 and Q2 are complete.  And if I'm looking at it monthly then January through August are complete, but September is not.

Cells B5 and D5 look exactly as I expect and want them to be. On row 6 below under each "Gross Annualized" value I have basically just put the formula for what it's actually doing.

What I would like to see in the blue cell is $67,211,697,268 - essentially the most recent annualization for a completed period. The annualization for Q3 is misleading because the quarter has not yet completed.  There's $16b in Q1 and $17b in Q2, so the measly $78m in Q3 (yellow cell) is dragging the annualization down significantly. Even worse, the Gross Amount for Q4 is being treated as a $0.00, which is further dragging down the "2015 Gross Annualized" amount in blue. In a T-SQL average calculation, for example, I think the green cell would be treated as NULL rather than $0.  That's kind of the behavior I want.

So I would like to do two things:

Create a calculation (probably just a 0 or 1 flag) that indicates whether the current period is complete or not.  Again, using 9/9/2015 as an example, Q2 would be complete but Q3 would not be. And August would be complete, but September would not. Make the blue cell show $67,211,697,268 - an annualization based on completed quarters only.

For whatever it's worth here is the current calculation for Gross Annualized.

CREATE MEMBER CURRENTCUBE.[Measures].[Gross YTD]
AS AGGREGATE(
YTD([Pay Date].[Calendar].CurrentMember)
,[Measures].[Gross Amount]),
FORMAT_STRING = "Currency",
VISIBLE = 0;

[Code] .....

View 2 Replies View Related

Analysis :: Average Calculation On Leaf And Aggregate Parent Level And Above Using Averaged Value?

Sep 14, 2015

At the 2nd level, the calculated measure will only be correct if it is Averaged. And at the 1st level, the calculated measure will only be correct to take these Average value from 2nd level and Sum then up together. 

Level 1 Level 2
A    
X1
X2
=================
(Avg of X1 + X2)  
B
Y1
Y2
Y3
=================
(Avg of Y1 + Y2 + Y3)
===================================================
(Sum of (Avg of X1 + X2)  + (Avg of Y1 + Y2 + Y3) )

Currently, Instead of summing all the 3 averaged value, it is averaging against all the items like,

(Avg of X1 + X2 + Y1 + Y2 + Y3)

My MDX currently looks something like that 

[Measure].[Value] / [Dimension].[Attribute.count] -> so i can get the avarage at the 2nd level but it doesn't require on the 1st level but retaining this value.

How can i do an average on the leaf level and using these average values to sum at parent level?

View 4 Replies View Related

Analysis :: Calculation Of average Using DAX AVERAGE And AVERAGEX

Jun 21, 2015

Calculation of an average using DAX' AVERAGE and AVERAGEX.This is the manual calculation in DW, using SQL.In the tabular project (we're i've noticed that these 4 %'s are in itself strange), in a 1st moment i've noticed that i would have to divide by 100 to get the same values as in the DW, so i've used AVERAGEX:

Avg_AMP:=AVERAGEX('Fct Sales';'Fct Sales'[_AMP]/100)
Avg_AMPdollar:=AVERAGEX('Fct Sales';'Fct Sales'[_AMPdollar]/100)
Avg_FMP:=AVERAGEX('Fct Sales';'Fct Sales'[_FMP]/100)
Avg_FMPdollar:=AVERAGEX('Fct Sales';'Fct Sales'[_FMPdollar]/100)

The results were, respectively: 701,68; 2120,60...; -669,441; and  finally **-694,74** for Avg_FMPdollar.i can't understand the difference to SQL calculation, since calculations are similar to the other ones. After that i've tried:

test:=SUM([_FMPdollar])/countrows('Fct Sales') AND the value was EQUAL to SQL: -672,17
test2:=AVERAGE('Fct Sales'[_Frontend Margin Percent ACY]), and here, without dividing by 100 in the end, -696,74...

So, AVERAGE and AVERAGEX have a diferent behaviour from the SUM divided by COUNTROWS, and even more strange, test2 doesn't need the division by 100 to be similar to AVERAGEX result.

I even calculated the number of blanks and number of zeros on each column, could it be a difference on the denominator (so, a division by a diferente number of rows), but they are equal on each row.

View 2 Replies View Related

Converting Oracle Calculation To Sql Server 2005 Calculation

Jul 19, 2007

Hi I am having to convert some oracle reports to Reporting Services. Where I am having difficulty is with the

calculations.

Oracle

TO_DATE(TO_CHAR(Visit Date+Visit Time/24/60/60,'DD-Mon-YYYY HH24:MISS'),'DD-Mon-YYYY HH24:MISS')



this is a sfar as I have got with the sql version

SQLSERVER2005

= DateAdd("s",Fields!VISIT_DATE.Value,Fields!VISIT_TIME.Value246060 )



visit_date is date datatype visit_time is number datatype. have removed : from MI(here)SS as was showing as smiley.



using:

VS 2005 BI Tools

SQLServer 2005



View 5 Replies View Related

Better Median??

Dec 7, 2002

I recently had to use my own little median technique again on a report here at work, and had posted it before, but wasn't sure if anyone had seen it. I have read Celko's and others techniques for generating a median and haven't seen one more efficent.

Does anyone have a better way they can think of? I think this bad boy is pretty short & efficient.

First, if you want to return the middle number or the higher one next to the middle if there is an even number:

SELECT x.Value AS median
FROM Vals x
CROSS JOIN Vals y
GROUP BY x.Value
HAVING SUM(SIGN(x.Value-y.Value)) IN (1,0)

Change the " IN (1,0)" to "IN (-1,0)" to get the lower value if there is an even # of values.

Basically, we are saying compare each number to all possible numbers, and add up values of 1,0 or -1 depending if the first number is less, equal or higher than the second. The number that returns 0 is right in the middle ... If there is no middle, a -1 or 1 is returned. There will never be a 0 and (-1 or 1) at the same time returned.

To get the financial median (avg of the 2 values middle values if there is an even number), you need to encapsulate the results of the above into a subquery, allow for not just (-1,0) but all three (-1,0,1) and then take the AVG of the values returned.

That is,

SELECT Avg(Median) as Median FROM
(
SELECT x.Value AS median
FROM Vals x
CROSS JOIN Vals y
GROUP BY x.Value
HAVING SUM(SIGN(x.Value-y.Value)) IN (1,0,-1)
) A

If there is an even number of values, the lower and higher middle ones are averaged. If there is an odd number, only the middle value is returned and averaged (which of course has no effect).

Most other techniques used several COUNT(*) subqueries which this one avoids.

Critique and enjoy!

- Jeff

View 7 Replies View Related

New To SQL, Need To Get The Median Value

Sep 27, 2007

I have a table that contains the following:
customer (ID of customers)
product (Product description numeric value)
UOM (unit of measure like each or pak)
avgprice (Avg proce that this product and uom was sold)


I need to find the median value for a product, uom. Then I need create a table that shows product,uom,avgprice,median grouped by product and uom
I have been at this for two days with no luck

Thanks in advance for any help




View 6 Replies View Related

Calculating Median In SQL

Aug 25, 2004

Hi All,
I have a table that of server names and their execution times that run in to hundreds of thousands of records. What i need is some SQL that gives me the median execution times for each of these different servers. At the moment i have some SQL that only gives me the median for all the records in the table not the median execution time for every different server name. For example my tables looks something like this;

ServerName | ExecTime
-----------------------
server1 | 0.07
server2 | 0.17
server1 | 0.27
server1 | 0.37
server2 | 0.47
server1 | 0.57
server1 | 0.67
server2 | 0.77

My SQL below gives me

ServerName | ExecTime
-----------------------
server1 | 0.37

Where as i want

ServerName | ExecTime
-----------------------
server1 | 0.37
server2 | 0.47

Here is my SQL, hope someone can modify it and thanks in advance.


Code:


SELECT DISTINCT instance, exec_time AS median
FROM (SELECT instance, exec_time
FROM (SELECT TOP 1 exec_time = exec_time * 1.0, instance
FROM (SELECT TOP 50 PERCENT exec_time, instance
FROM llserverlogs
ORDER BY exec_time) sub_a
ORDER BY 1 DESC) sub_1
UNION ALL
SELECT instance, exec_time
FROM (SELECT TOP 1 exec_time = exec_time * 1.0, instance
FROM (SELECT TOP 50 PERCENT exec_time, instance
FROM llserverlogs
ORDER BY exec_time DESC) sub_b
ORDER BY 1) sub_2)

View 4 Replies View Related

How To Find The Median?

Jan 28, 2006

I've noticed that SQL Server (and other DBMSs I've looked at) doesn't seem to have a built-in function for finding the median of a range of numbers.

Gack!

View 14 Replies View Related

Median Function

Sep 28, 2006

I have a long term need for a median function, I was wondering if anyone has or knows of some code or user defined functions somewhere that would do this. Ideally you could use it just liket the rest of the aggregate functions like AVG, etc.

View 1 Replies View Related

Finding Median Value

Mar 12, 2007

Hi,

I have looked all over the web to try to find some very basic / simple explanations of how to get a median value from a group of records in a table but with no luck

the problem i am having is that all the information i find is always centered around getting a median using every single row in the table. except i have groups of data in the table and want to work out a median for each group. the group is identified by 4 different columns (the 5th column is what i want to get the median on but for each group not the entire table) and i want to produce a resulting table that has 1 row for each group and therefore contains the median value for the group instead of the individual numbers that it currently has. e.g. the current table is like this

column1 column2 column3 column 4 column5(median of this)

value 1 value 2 value 3 value 4 1.2
value 1 value 2 value 3 value 4 1.0
value 1 value 2 value 3 value 4 1.5
value 2 value 3 value 4 value 5 0.2
value 2 value 3 value 4 value 5 0.4
etc...

and i need a query to get the results to show like this

column1 column2 column3 column 4 column5

value 1 value 2 value 3 value 4 1.0
value 2 value 3 value 4 value 5 0.3
etc...

This is driving me crazy and i will be very helpful if anyone can help

the statement i need to add it to is:

select pat_demid, pat_lastname, meas_gendate, meas_id, test_gendate, avg(srtot)as meansrtot, avg(sreff)as meansreff, avg(BFRaw)as BF_Rawmean, avg(BFTGV)as BF_TGVmean, count(srtot)as countsrtot, count(sreff)as countsreff
from bodyparametersf
where (srtot is not null) OR (sreff is not null)
group by pat_demid, pat_lastname, meas_gendate, meas_id, test_gendate

thanks very much

View 16 Replies View Related

Calculate Median!!!

May 29, 2007

I need to calculate Median on each calculated result from the query below. There is one Median function available in SQL2K but it is not working. Can anyone help me in this regard.

------------------------------------------------------------------------
SELECT INS.Code As [code],INS.FinYr as [YEAR], ' ' As [FIRE BUSINESS], (INSRev.FI_NetPremLessIns / INSRev.FI_GrPremium) * 100 As [Rention Ratio],
(INSRev.FI_NetClaimPaid/INSRev.FI_AdjNetPremium)*100 As [Claim Ratio], ((INSRev.FI_AgencyCommPaid+INSRev.FI_ReInsCommPaid+INSRev.FI_MgmtExpenses+INSRev.FI_OthExpenses)/INSRev.FI_AdjNetPremium)*100 As [Expense Ratio],
((INSRev.FI_NetClaimPaid/INSRev.FI_AdjNetPremium)*100)+(((INSRev.FI_AgencyCommPaid+INSRev.FI_ReInsCommPaid+INSRev.FI_MgmtExpe nses+INSRev.FI_OthExpenses)/INSRev.FI_AdjNetPremium)*100) As [Combine Ratio],
(INSRev.FI_ClosingBal/INSRev.FI_NetClaimPaid) As [Unexpired Risk Reserve to Net Claim(x)],(INSRev.FI_MgmtExpenses/INSRev.FI_AdjNetPremium)*100 As [Management Expenses to Adj. Net Premium],
(INSRev.FI_AgencyCommPaid/INSRev.FI_AdjNetPremium)*100 As [Agency Commissioned to Adj. Net Premium]

FROM
(InsuranceGen As INS LEFT JOIN INSURANCEGen As INS1 ON (INS1.FinYr=INS.FinYr-1 AND INS.Code=INS1.Code))
LEFT JOIN INSRevGen as INSRev ON (INS.Code=INSRev.Code AND INS.FinYr=INSRev.FinYr) WHERE INS.Code IN ('ABC1','ABC2','ABC3') AND INS.FinYr=2005 ORDER BY INS.Code, INS.FinYr
----------------------------------------------------------------------

Thanks

View 5 Replies View Related

Median Function

Sep 7, 2007

Im trying to find a funtion for median's if there is one. can anyone help?

View 3 Replies View Related

Calculate Median LTM

Apr 22, 2008

Using SQL Server 2005, I have the following query to calculate the median sales of each quarter over the past 5 years:


WITH CompMedian AS

(

SELECT SoldDate, SoldPrice, ROW_NUMBER() OVER(PARTITION BY Convert(Varchar(5),Year(SoldDate)) + Convert(Varchar(5), RIGHT(CAST(100+DATEPART(QQ,SoldDate) AS CHAR(3)), 2)) ORDER BY SoldPrice) AS RowNum, COUNT(*) OVER(PARTITION BY Convert(Varchar(5),Year(SoldDate)) + Convert(Varchar(5), RIGHT(CAST(100+DATEPART(QQ,SoldDate) AS CHAR(3)), 2))) AS Cnt FROM tbl_Orders
WHERE Status = 'Sold'

AND SoldDate >= DATEADD(Year, -5, Convert(DateTime, Convert(Varchar(5),Month(GetDate())) + Convert(Varchar(5), '/1/') + Convert(Varchar(5), YEAR(GetDate()))))

AND SoldDate < DATEADD(Year, 0, Convert(DateTime, Convert(Varchar(5),Month(GetDate())) + Convert(Varchar(5), '/1/') + Convert(Varchar(5), YEAR(GetDate()))))
)

SELECT Convert(Varchar(5),Year(SoldDate)) + Convert(Varchar(5), RIGHT(CAST(100+DATEPART(QQ,SoldDate) AS CHAR(3)), 2)) AS CompDate, AVG(SoldPrice) AS CompMedian

FROM CompMedian

WHERE RowNum IN((Cnt + 1) / 2, (Cnt + 2) / 2)

GROUP BY Convert(Varchar(5),Year(SoldDate)) + Convert(Varchar(5), RIGHT(CAST(100+DATEPART(QQ,SoldDate) AS CHAR(3)), 2))

ORDER BY CompDate;


Now my client would like me to change the query so that each quarter would represent the median for the past 12 months ending with that quarter. I've been looking at this for hours and I'm at a loss. Anyone have any thoughts?

Thanks in advance,
Russ

View 2 Replies View Related

Calculate Median Value

Dec 15, 2005

I am converting a report created using Crystal Reports 10 to Reporting Services.  The report contains a list of items with dollar values.  The original report displays both the Average and Median value.  I can easily ( using avg(Field1.Value!) ) determine the average but cannot find a function to determine the median.

How can I add the Median to the report?

 

Thanks in advance,

Greg

View 21 Replies View Related

Median Query Without Using Function

Feb 24, 2006

I have a table (cars) with 3 fields:VIN, Class, sell_price101, sports, 10000102, sports, 11000103, luxury, 9000104, sports, 11000105, sports, 11000106, luxury, 5000107, sports, 11000108, sports, 11000109, luxury, 9000i need to write a query that WITHOUT USING A FUNCTION will return themedian selling price for each class of car. result should look like:Class, Med_Priceluxury, 9000sports, 11000thanks to all u SQLers

View 4 Replies View Related

The Median Function In SQL Server

Jul 20, 2005

I read the follow query about calculating median posted by Daivd Portaon 10/8/03.CREATE TABLE SomeValues (keyx CHAR(1) PRIMARY KEY, valuex INTEGER NOTNULL)INSERT INTO SomeValues VALUES ('A',1)INSERT INTO SomeValues VALUES ('B',2)INSERT INTO SomeValues VALUES ('C',3)INSERT INTO SomeValues VALUES ('D',4)INSERT INTO SomeValues VALUES ('E',5)SELECT S1.valuex AS medianFROM SomeValues AS S1, SomeValues AS S2GROUP BY S1.valuexHAVING SUM(CASE WHEN S2.valuex <= S1.valuexTHEN 1 ELSE 0 END)[color=blue]>= ((COUNT(*) + 1) / 2)[/color]AND SUM(CASE WHEN S2.valuex >= S1.valuexTHEN 1 ELSE 0 END)[color=blue]>= (COUNT(*)/2 + 1)[/color]I have difficulty to understand the having clause. If S1 and S2 arethe same table, what it means by S2.valuex >= S1.valuex? Could somegive me a help?Also, if I have a table structured as:classID field1 field2 field3c1 1 2 3c1 4 5 6c1 7 8 9c2 9 8 7c2 6 5 4c2 3 2 1Is there a way to create a user-defined function that can get themedian for each field as easy as the average function. Such asselect distinct classID,median(field1),median(field2),median(field3)from [tablename]group by classIDThanks in advance

View 2 Replies View Related

Median Function In T-SQL For SS2005?

Oct 13, 2006

Hello!

I have been trying to find a T-SQL function that would calculates a Median statistical value for me. I am runnnig on SS 2005? Any examples of using this function would be greatly appreciated.

Thanks for any responses!





View 7 Replies View Related

Using Report Builder 3.0 To Calculate Median?

Sep 14, 2015

I'm using custom code in an expression to calculate the median of a column. It works fine up to a point. Like if there are 35 rows in the result set (or up to some number) but when it gets bigger results, like 42 rows or more it doesn't work, the median is -1. This is the custom code I'm using (found online).

I don't see anything limiting the count, but it comes back with a -1 median so I think that means the count is not > 0.

I have a column in the report called arrival_to_complete which is like: 53 min

I create a column with expression: =MAX(Code.AddValue(Val(Fields!Arrival_to_complete.Value))) to fill the array using just the number part of the column. Then in the report I have 'Median =' <expression>, where the expression is: =Code.GetMedian() I run the report with 2 parameters a begin date and an end date. I don't see where any of this should be limiting the median calculation so I don't get why it works sometimes and not other times.

Dim values As New System.Collections.ArrayList
Function AddValue(newValue As Decimal)
If values is Nothing Then
values = New System.Collections.ArrayList
End If
values.Add(newValue)

[code]....

View 0 Replies View Related

Calculating Median Value From Measures And Dimensions

May 24, 2007

I am facing some problem in calculating Median

I am trying to calculate the median value using one of the measures and a dimension value.



Time is a measure in my cube and OpId is one of the dimensions.The result is as follows:



opid time median

1 55

2 23

3 23

Total 23



The Time here for Op Id 1 is the aggregation for all the rows whose OpId is 1.I want the median of the values whose OpId is 1 which is not showing at the moment.



What I am getting here is the median for all of the OpId but what I really want is the median for each of the individual Opid's as well.



I am using a calculated field Median with the following expression.



MEDIAN

( [Dim Operation].[Dim Operation].currentmember.children ,[Measures].[Elapsed Time])



Thanks

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved