PC Review


Reply
Thread Tools Rate Thread

basMedian obtaining quarterly results

 
 
rdcsfd
Guest
Posts: n/a
 
      12th Feb 2010
I'm using the following query to get quarterly results for each bedroom
number. The median function is returning the same number for each bedroom
number in each quarter. Can someone tell me how to get it to provide the
median price by bedroom number?

SELECT DISTINCTROW Sales2.City, Format$([Sales2].[Selling Date],'\Qq yyyy')
AS [Quarter], Sales2.[Property Subtype 1], Sales2.Bedrooms AS [Bedrooms],
Avg(Sales2.[Selling Price]) AS [Average Price],
Format$(CDbl(acbDMedian("[Selling Price]","Sales2","Format$([Selling
Date],'\Qq yyyy') = '" & Format$(Sales2.[Selling Date],'\Qq yyyy') &
"'")),'$#,###') AS [Median Price], Min(Sales2.[Selling Price]) AS [Lowest
Price], Max(Sales2.[Selling Price]) AS [Highest Price], Count(*) AS [# Sold]
FROM Sales2
WHERE Sales2.City = 'Santa Rosa' AND Sales2.[Property Subtype 1] = 'Cond'
GROUP BY Sales2.City, Format$([Sales2].[Selling Date],'\Qq yyyy'),
Sales2.[Property Subtype 1], Sales2.Bedrooms, Year([Sales2].[Selling
Date])*4+DatePart('q',[Sales2].[Selling Date])-1;

Here are the results from the above query:
City Quarter Type Bedrooms Average Median
Santa Rosa Q1 2003 COND 1 $163,666.67 $375,000
Santa Rosa Q1 2003 COND 2 $238,704.17 $375,000
Santa Rosa Q1 2003 COND 3 $292,577.59 $375,000
Santa Rosa Q1 2003 COND 4 $420,000.00 $375,000
Santa Rosa Q1 2004 COND 1 $184,909.09 $425,000
Santa Rosa Q1 2004 COND 2 $272,024.92 $425,000
Santa Rosa Q1 2004 COND 3 $333,270.00 $425,000
Santa Rosa Q1 2004 COND 4 $277,000.00 $425,000

TIA
 
Reply With Quote
 
 
 
 
Tokyo Alex
Guest
Posts: n/a
 
      12th Feb 2010
Hi,

I think this will work (Air Code):
Format$(CDbl(acbDMedian("[Selling Price]","Sales2","Format$([Selling
Date],'\Qq yyyy') = '" & Format$(Sales2.[Selling Date],'\Qq yyyy') & " AND
Sales2.Bedrooms = " & Sales2.Bedrooms)),'$#,###') AS [Median Price]

Assumptions:
1) acbDMedian takes the same kind of arguments as the VBA 'DAvg' function.
2) Sales2.Bedrooms is a numeric field.

Hope this helps,
Alex.


"rdcsfd" wrote:

> I'm using the following query to get quarterly results for each bedroom
> number. The median function is returning the same number for each bedroom
> number in each quarter. Can someone tell me how to get it to provide the
> median price by bedroom number?
>
> SELECT DISTINCTROW Sales2.City, Format$([Sales2].[Selling Date],'\Qq yyyy')
> AS [Quarter], Sales2.[Property Subtype 1], Sales2.Bedrooms AS [Bedrooms],
> Avg(Sales2.[Selling Price]) AS [Average Price],
> Format$(CDbl(acbDMedian("[Selling Price]","Sales2","Format$([Selling
> Date],'\Qq yyyy') = '" & Format$(Sales2.[Selling Date],'\Qq yyyy') &
> "'")),'$#,###') AS [Median Price], Min(Sales2.[Selling Price]) AS [Lowest
> Price], Max(Sales2.[Selling Price]) AS [Highest Price], Count(*) AS [# Sold]
> FROM Sales2
> WHERE Sales2.City = 'Santa Rosa' AND Sales2.[Property Subtype 1] = 'Cond'
> GROUP BY Sales2.City, Format$([Sales2].[Selling Date],'\Qq yyyy'),
> Sales2.[Property Subtype 1], Sales2.Bedrooms, Year([Sales2].[Selling
> Date])*4+DatePart('q',[Sales2].[Selling Date])-1;
>
> Here are the results from the above query:
> City Quarter Type Bedrooms Average Median
> Santa Rosa Q1 2003 COND 1 $163,666.67 $375,000
> Santa Rosa Q1 2003 COND 2 $238,704.17 $375,000
> Santa Rosa Q1 2003 COND 3 $292,577.59 $375,000
> Santa Rosa Q1 2003 COND 4 $420,000.00 $375,000
> Santa Rosa Q1 2004 COND 1 $184,909.09 $425,000
> Santa Rosa Q1 2004 COND 2 $272,024.92 $425,000
> Santa Rosa Q1 2004 COND 3 $333,270.00 $425,000
> Santa Rosa Q1 2004 COND 4 $277,000.00 $425,000
>
> TIA

 
Reply With Quote
 
Tokyo Alex
Guest
Posts: n/a
 
      12th Feb 2010
Hi again,

Thinking about it, you'll also need to include the 'Santa Rosa' and 'Cond'
conditions in the acbDMedian call, or else you'll get the median across all
cities and property types.

Format$(CDbl(acbDMedian("[Selling Price]","Sales2","Format$([Selling
Date],'\Qq yyyy') = '" & Format$(Sales2.[Selling Date],'\Qq yyyy') & " AND
Sales2.Bedrooms = " & Sales2.Bedrooms &" Sales2.City = 'Santa Rosa' AND
Sales2.[Property Subtype 1] = 'Cond'")),'$#,###') AS [Median Price]

This should help more

Alex.




"Tokyo Alex" wrote:

> Hi,
>
> I think this will work (Air Code):
> Format$(CDbl(acbDMedian("[Selling Price]","Sales2","Format$([Selling
> Date],'\Qq yyyy') = '" & Format$(Sales2.[Selling Date],'\Qq yyyy') & " AND
> Sales2.Bedrooms = " & Sales2.Bedrooms)),'$#,###') AS [Median Price]
>
> Assumptions:
> 1) acbDMedian takes the same kind of arguments as the VBA 'DAvg' function.
> 2) Sales2.Bedrooms is a numeric field.
>
> Hope this helps,
> Alex.
>
>
> "rdcsfd" wrote:
>
> > I'm using the following query to get quarterly results for each bedroom
> > number. The median function is returning the same number for each bedroom
> > number in each quarter. Can someone tell me how to get it to provide the
> > median price by bedroom number?
> >
> > SELECT DISTINCTROW Sales2.City, Format$([Sales2].[Selling Date],'\Qq yyyy')
> > AS [Quarter], Sales2.[Property Subtype 1], Sales2.Bedrooms AS [Bedrooms],
> > Avg(Sales2.[Selling Price]) AS [Average Price],
> > Format$(CDbl(acbDMedian("[Selling Price]","Sales2","Format$([Selling
> > Date],'\Qq yyyy') = '" & Format$(Sales2.[Selling Date],'\Qq yyyy') &
> > "'")),'$#,###') AS [Median Price], Min(Sales2.[Selling Price]) AS [Lowest
> > Price], Max(Sales2.[Selling Price]) AS [Highest Price], Count(*) AS [# Sold]
> > FROM Sales2
> > WHERE Sales2.City = 'Santa Rosa' AND Sales2.[Property Subtype 1] = 'Cond'
> > GROUP BY Sales2.City, Format$([Sales2].[Selling Date],'\Qq yyyy'),
> > Sales2.[Property Subtype 1], Sales2.Bedrooms, Year([Sales2].[Selling
> > Date])*4+DatePart('q',[Sales2].[Selling Date])-1;
> >
> > Here are the results from the above query:
> > City Quarter Type Bedrooms Average Median
> > Santa Rosa Q1 2003 COND 1 $163,666.67 $375,000
> > Santa Rosa Q1 2003 COND 2 $238,704.17 $375,000
> > Santa Rosa Q1 2003 COND 3 $292,577.59 $375,000
> > Santa Rosa Q1 2003 COND 4 $420,000.00 $375,000
> > Santa Rosa Q1 2004 COND 1 $184,909.09 $425,000
> > Santa Rosa Q1 2004 COND 2 $272,024.92 $425,000
> > Santa Rosa Q1 2004 COND 3 $333,270.00 $425,000
> > Santa Rosa Q1 2004 COND 4 $277,000.00 $425,000
> >
> > TIA

 
Reply With Quote
 
Tokyo Alex
Guest
Posts: n/a
 
      12th Feb 2010
Oops, forgot an 'AND' before the new criteria.

3rd time round:
Format$(CDbl(acbDMedian("[Selling Price]","Sales2","Format$([Selling
Date],'\Qq yyyy') = '" & Format$(Sales2.[Selling Date],'\Qq yyyy') & " AND
Sales2.Bedrooms = " & Sales2.Bedrooms &" AND Sales2.City = 'Santa Rosa' AND
Sales2.[Property Subtype 1] = 'Cond'")),'$#,###') AS [Median Price]

Alex.


"Tokyo Alex" wrote:

> Hi again,
>
> Thinking about it, you'll also need to include the 'Santa Rosa' and 'Cond'
> conditions in the acbDMedian call, or else you'll get the median across all
> cities and property types.
>
> Format$(CDbl(acbDMedian("[Selling Price]","Sales2","Format$([Selling
> Date],'\Qq yyyy') = '" & Format$(Sales2.[Selling Date],'\Qq yyyy') & " AND
> Sales2.Bedrooms = " & Sales2.Bedrooms &" Sales2.City = 'Santa Rosa' AND
> Sales2.[Property Subtype 1] = 'Cond'")),'$#,###') AS [Median Price]
>
> This should help more
>
> Alex.
>
>
>
>
> "Tokyo Alex" wrote:
>
> > Hi,
> >
> > I think this will work (Air Code):
> > Format$(CDbl(acbDMedian("[Selling Price]","Sales2","Format$([Selling
> > Date],'\Qq yyyy') = '" & Format$(Sales2.[Selling Date],'\Qq yyyy') & " AND
> > Sales2.Bedrooms = " & Sales2.Bedrooms)),'$#,###') AS [Median Price]
> >
> > Assumptions:
> > 1) acbDMedian takes the same kind of arguments as the VBA 'DAvg' function.
> > 2) Sales2.Bedrooms is a numeric field.
> >
> > Hope this helps,
> > Alex.
> >
> >
> > "rdcsfd" wrote:
> >
> > > I'm using the following query to get quarterly results for each bedroom
> > > number. The median function is returning the same number for each bedroom
> > > number in each quarter. Can someone tell me how to get it to provide the
> > > median price by bedroom number?
> > >
> > > SELECT DISTINCTROW Sales2.City, Format$([Sales2].[Selling Date],'\Qq yyyy')
> > > AS [Quarter], Sales2.[Property Subtype 1], Sales2.Bedrooms AS [Bedrooms],
> > > Avg(Sales2.[Selling Price]) AS [Average Price],
> > > Format$(CDbl(acbDMedian("[Selling Price]","Sales2","Format$([Selling
> > > Date],'\Qq yyyy') = '" & Format$(Sales2.[Selling Date],'\Qq yyyy') &
> > > "'")),'$#,###') AS [Median Price], Min(Sales2.[Selling Price]) AS [Lowest
> > > Price], Max(Sales2.[Selling Price]) AS [Highest Price], Count(*) AS [# Sold]
> > > FROM Sales2
> > > WHERE Sales2.City = 'Santa Rosa' AND Sales2.[Property Subtype 1] = 'Cond'
> > > GROUP BY Sales2.City, Format$([Sales2].[Selling Date],'\Qq yyyy'),
> > > Sales2.[Property Subtype 1], Sales2.Bedrooms, Year([Sales2].[Selling
> > > Date])*4+DatePart('q',[Sales2].[Selling Date])-1;
> > >
> > > Here are the results from the above query:
> > > City Quarter Type Bedrooms Average Median
> > > Santa Rosa Q1 2003 COND 1 $163,666.67 $375,000
> > > Santa Rosa Q1 2003 COND 2 $238,704.17 $375,000
> > > Santa Rosa Q1 2003 COND 3 $292,577.59 $375,000
> > > Santa Rosa Q1 2003 COND 4 $420,000.00 $375,000
> > > Santa Rosa Q1 2004 COND 1 $184,909.09 $425,000
> > > Santa Rosa Q1 2004 COND 2 $272,024.92 $425,000
> > > Santa Rosa Q1 2004 COND 3 $333,270.00 $425,000
> > > Santa Rosa Q1 2004 COND 4 $277,000.00 $425,000
> > >
> > > TIA

 
Reply With Quote
 
rdcsfd
Guest
Posts: n/a
 
      12th Feb 2010
Thanks for the try, but it now gives me a spurious median price:

City Quarter Type Bedrooms Average Median
Santa Rosa Q1 2003 COND 1 $163,666.67 $3,061
Santa Rosa Q1 2003 COND 2 $238,704.17 $3,061
Santa Rosa Q1 2003 COND 3 $292,577.59 $3,061
Santa Rosa Q1 2003 COND 4 $420,000.00 $3,061
Santa Rosa Q1 2004 COND 1 $184,909.09 $3,061
Santa Rosa Q1 2004 COND 2 $272,024.92 $3,061
Santa Rosa Q1 2004 COND 3 $333,270.00 $3,061
Santa Rosa Q1 2004 COND 4 $277,000.00 $3,061


"Tokyo Alex" wrote:

> Oops, forgot an 'AND' before the new criteria.
>
> 3rd time round:
> Format$(CDbl(acbDMedian("[Selling Price]","Sales2","Format$([Selling
> Date],'\Qq yyyy') = '" & Format$(Sales2.[Selling Date],'\Qq yyyy') & " AND
> Sales2.Bedrooms = " & Sales2.Bedrooms &" AND Sales2.City = 'Santa Rosa' AND
> Sales2.[Property Subtype 1] = 'Cond'")),'$#,###') AS [Median Price]
>
> Alex.
>
>
> "Tokyo Alex" wrote:
>
> > Hi again,
> >
> > Thinking about it, you'll also need to include the 'Santa Rosa' and 'Cond'
> > conditions in the acbDMedian call, or else you'll get the median across all
> > cities and property types.
> >
> > Format$(CDbl(acbDMedian("[Selling Price]","Sales2","Format$([Selling
> > Date],'\Qq yyyy') = '" & Format$(Sales2.[Selling Date],'\Qq yyyy') & " AND
> > Sales2.Bedrooms = " & Sales2.Bedrooms &" Sales2.City = 'Santa Rosa' AND
> > Sales2.[Property Subtype 1] = 'Cond'")),'$#,###') AS [Median Price]
> >
> > This should help more
> >
> > Alex.
> >
> >
> >
> >
> > "Tokyo Alex" wrote:
> >
> > > Hi,
> > >
> > > I think this will work (Air Code):
> > > Format$(CDbl(acbDMedian("[Selling Price]","Sales2","Format$([Selling
> > > Date],'\Qq yyyy') = '" & Format$(Sales2.[Selling Date],'\Qq yyyy') & " AND
> > > Sales2.Bedrooms = " & Sales2.Bedrooms)),'$#,###') AS [Median Price]
> > >
> > > Assumptions:
> > > 1) acbDMedian takes the same kind of arguments as the VBA 'DAvg' function.
> > > 2) Sales2.Bedrooms is a numeric field.
> > >
> > > Hope this helps,
> > > Alex.
> > >
> > >
> > > "rdcsfd" wrote:
> > >
> > > > I'm using the following query to get quarterly results for each bedroom
> > > > number. The median function is returning the same number for each bedroom
> > > > number in each quarter. Can someone tell me how to get it to provide the
> > > > median price by bedroom number?
> > > >
> > > > SELECT DISTINCTROW Sales2.City, Format$([Sales2].[Selling Date],'\Qq yyyy')
> > > > AS [Quarter], Sales2.[Property Subtype 1], Sales2.Bedrooms AS [Bedrooms],
> > > > Avg(Sales2.[Selling Price]) AS [Average Price],
> > > > Format$(CDbl(acbDMedian("[Selling Price]","Sales2","Format$([Selling
> > > > Date],'\Qq yyyy') = '" & Format$(Sales2.[Selling Date],'\Qq yyyy') &
> > > > "'")),'$#,###') AS [Median Price], Min(Sales2.[Selling Price]) AS [Lowest
> > > > Price], Max(Sales2.[Selling Price]) AS [Highest Price], Count(*) AS [# Sold]
> > > > FROM Sales2
> > > > WHERE Sales2.City = 'Santa Rosa' AND Sales2.[Property Subtype 1] = 'Cond'
> > > > GROUP BY Sales2.City, Format$([Sales2].[Selling Date],'\Qq yyyy'),
> > > > Sales2.[Property Subtype 1], Sales2.Bedrooms, Year([Sales2].[Selling
> > > > Date])*4+DatePart('q',[Sales2].[Selling Date])-1;
> > > >
> > > > Here are the results from the above query:
> > > > City Quarter Type Bedrooms Average Median
> > > > Santa Rosa Q1 2003 COND 1 $163,666.67 $375,000
> > > > Santa Rosa Q1 2003 COND 2 $238,704.17 $375,000
> > > > Santa Rosa Q1 2003 COND 3 $292,577.59 $375,000
> > > > Santa Rosa Q1 2003 COND 4 $420,000.00 $375,000
> > > > Santa Rosa Q1 2004 COND 1 $184,909.09 $425,000
> > > > Santa Rosa Q1 2004 COND 2 $272,024.92 $425,000
> > > > Santa Rosa Q1 2004 COND 3 $333,270.00 $425,000
> > > > Santa Rosa Q1 2004 COND 4 $277,000.00 $425,000
> > > >
> > > > TIA

 
Reply With Quote
 
Tokyo Alex
Guest
Posts: n/a
 
      13th Feb 2010
What happens if you replace the 'acbDMedian' with 'DAvg'? Does it give the
same result as your [Average Price] field?

Alex.


"rdcsfd" wrote:

> Thanks for the try, but it now gives me a spurious median price:
>
> City Quarter Type Bedrooms Average Median
> Santa Rosa Q1 2003 COND 1 $163,666.67 $3,061
> Santa Rosa Q1 2003 COND 2 $238,704.17 $3,061
> Santa Rosa Q1 2003 COND 3 $292,577.59 $3,061
> Santa Rosa Q1 2003 COND 4 $420,000.00 $3,061
> Santa Rosa Q1 2004 COND 1 $184,909.09 $3,061
> Santa Rosa Q1 2004 COND 2 $272,024.92 $3,061
> Santa Rosa Q1 2004 COND 3 $333,270.00 $3,061
> Santa Rosa Q1 2004 COND 4 $277,000.00 $3,061
>
>
> "Tokyo Alex" wrote:
>
> > Oops, forgot an 'AND' before the new criteria.
> >
> > 3rd time round:
> > Format$(CDbl(acbDMedian("[Selling Price]","Sales2","Format$([Selling
> > Date],'\Qq yyyy') = '" & Format$(Sales2.[Selling Date],'\Qq yyyy') & " AND
> > Sales2.Bedrooms = " & Sales2.Bedrooms &" AND Sales2.City = 'Santa Rosa' AND
> > Sales2.[Property Subtype 1] = 'Cond'")),'$#,###') AS [Median Price]
> >
> > Alex.
> >
> >
> > "Tokyo Alex" wrote:
> >
> > > Hi again,
> > >
> > > Thinking about it, you'll also need to include the 'Santa Rosa' and 'Cond'
> > > conditions in the acbDMedian call, or else you'll get the median across all
> > > cities and property types.
> > >
> > > Format$(CDbl(acbDMedian("[Selling Price]","Sales2","Format$([Selling
> > > Date],'\Qq yyyy') = '" & Format$(Sales2.[Selling Date],'\Qq yyyy') & " AND
> > > Sales2.Bedrooms = " & Sales2.Bedrooms &" Sales2.City = 'Santa Rosa' AND
> > > Sales2.[Property Subtype 1] = 'Cond'")),'$#,###') AS [Median Price]
> > >
> > > This should help more
> > >
> > > Alex.
> > >
> > >
> > >
> > >
> > > "Tokyo Alex" wrote:
> > >
> > > > Hi,
> > > >
> > > > I think this will work (Air Code):
> > > > Format$(CDbl(acbDMedian("[Selling Price]","Sales2","Format$([Selling
> > > > Date],'\Qq yyyy') = '" & Format$(Sales2.[Selling Date],'\Qq yyyy') & " AND
> > > > Sales2.Bedrooms = " & Sales2.Bedrooms)),'$#,###') AS [Median Price]
> > > >
> > > > Assumptions:
> > > > 1) acbDMedian takes the same kind of arguments as the VBA 'DAvg' function.
> > > > 2) Sales2.Bedrooms is a numeric field.
> > > >
> > > > Hope this helps,
> > > > Alex.
> > > >
> > > >
> > > > "rdcsfd" wrote:
> > > >
> > > > > I'm using the following query to get quarterly results for each bedroom
> > > > > number. The median function is returning the same number for each bedroom
> > > > > number in each quarter. Can someone tell me how to get it to provide the
> > > > > median price by bedroom number?
> > > > >
> > > > > SELECT DISTINCTROW Sales2.City, Format$([Sales2].[Selling Date],'\Qq yyyy')
> > > > > AS [Quarter], Sales2.[Property Subtype 1], Sales2.Bedrooms AS [Bedrooms],
> > > > > Avg(Sales2.[Selling Price]) AS [Average Price],
> > > > > Format$(CDbl(acbDMedian("[Selling Price]","Sales2","Format$([Selling
> > > > > Date],'\Qq yyyy') = '" & Format$(Sales2.[Selling Date],'\Qq yyyy') &
> > > > > "'")),'$#,###') AS [Median Price], Min(Sales2.[Selling Price]) AS [Lowest
> > > > > Price], Max(Sales2.[Selling Price]) AS [Highest Price], Count(*) AS [# Sold]
> > > > > FROM Sales2
> > > > > WHERE Sales2.City = 'Santa Rosa' AND Sales2.[Property Subtype 1] = 'Cond'
> > > > > GROUP BY Sales2.City, Format$([Sales2].[Selling Date],'\Qq yyyy'),
> > > > > Sales2.[Property Subtype 1], Sales2.Bedrooms, Year([Sales2].[Selling
> > > > > Date])*4+DatePart('q',[Sales2].[Selling Date])-1;
> > > > >
> > > > > Here are the results from the above query:
> > > > > City Quarter Type Bedrooms Average Median
> > > > > Santa Rosa Q1 2003 COND 1 $163,666.67 $375,000
> > > > > Santa Rosa Q1 2003 COND 2 $238,704.17 $375,000
> > > > > Santa Rosa Q1 2003 COND 3 $292,577.59 $375,000
> > > > > Santa Rosa Q1 2003 COND 4 $420,000.00 $375,000
> > > > > Santa Rosa Q1 2004 COND 1 $184,909.09 $425,000
> > > > > Santa Rosa Q1 2004 COND 2 $272,024.92 $425,000
> > > > > Santa Rosa Q1 2004 COND 3 $333,270.00 $425,000
> > > > > Santa Rosa Q1 2004 COND 4 $277,000.00 $425,000
> > > > >
> > > > > TIA

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chart with Quarterly and Monthly Results =?Utf-8?B?R3JlZyBB?= Microsoft Excel Charting 0 14th May 2007 09:24 PM
Formula Help to Calculate Quarterly Results Paul Sheppard Microsoft Excel Misc 4 25th Jul 2006 06:23 AM
XNPV vs. NPV(quarterly) different results =?Utf-8?B?bWFnaXM=?= Microsoft Excel Worksheet Functions 3 6th Jan 2006 05:21 PM
Interesting coincidence --- ATi's quarterly results and the launch of the X1xxx series. John Lewis ATI Video Cards 3 1st Oct 2005 07:19 PM
Help on reporting Quarterly Results using VB Script Jean Microsoft VB .NET 2 3rd Oct 2003 11:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:26 AM.