Help with min/max qbe query

ChristineMD

Board Regular
Joined
Jul 29, 2008
Messages
53
Extracting data in a report by size.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Using the query grid, not writing SQL statements
<o:p></o:p>
Don't need to list every size, just the smallest size and the largest size - I'm using Min/Max in two separate columns to show the smallest size and the largest. <o:p></o:p>
The database has a numeric sort code ("size"), but of course the users don't want to see this, they want the label("sizecode"). Because the label for the sort code is text, it produces the ever so intuitive Microsoft sorting where 10 comes before 2. <o:p></o:p>
So using the sort code and min/max is successful. 1<SUP>st</SUP> column has the smallest size code, and the 2<SUP>nd</SUP> column has the largest size code.
<o:p></o:p>
but, What I want to do is sort by the numeric sort code, but display the label.

<o:p></o:p>
I tried using the statements below in the query grid in two separate columns,
Code:
SmSort: IIf(Min([size]),[Sizecode])<o:p></o:p>
LgSort: IIf(Max([size]),[Sizecode])

If I used "group" by with the above, got "cannot have aggregate function in group by clause

If I used "min/max" got "cannot hve function in aggregate expression"

Cannot not show totals, because other fields in the query depend on it.<o:p></o:p>
<o:p></o:p>
I also tried <o:p></o:p>
Rich (BB code):
 SmSort:  [sizecode] (with min([size]) in the criteria field)

... but that resulted in zero results. <o:p></o:p>
<o:p></o:p>If anyone thinks the underlying SQL would be helpful, let me know, I'm just not sure it would!


Any ideas? Thanks in advance!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
If you want both minimum and maximum in one query you might need subqueries.

I think we need to know more about what table(s) you have.

What is it you are trying to get the max/min size for anyway?

ie the largest/smallest what?
 
Upvote 0
I just figured out a way... seems kind of a cheat, but it works for me.

I used

Rich (BB code):
1st column:   Sm: [size] & " " & [sizecode]  (with Min in the total row)
2nd column:   Lg: [size] & " " & [sizecode]  (with Max in the total row)

It seems to be "minning" and "maxing" by only the [size] field, so it's working. It just shows the size code AND the label in the results.


Thanks for taking the time to respond Norie!
 
Upvote 0
Glad you've got it working.:)

You might need to watch out though.

If any of the size values go above 10 you might get some strange results.

I'm sure there's another way to do it 'properly' but if what you've got works that's the important thing.:)
 
Upvote 0
Even better, this works. Seems funny/hokey to me. But works is works.



Sm: Mid([size] & " " & [sizecode],7,15)
Lg: Mid([size] & " " & [sizecode],7,15)
 
Upvote 0
Are the labels actually numbers stored as text or are some of them alphanumeric?

If they are just numbers just stick Val round the field and they should sort properly.
Rich (BB code):
Val([sizecode])

Other conversion functions are available.
 
Upvote 0
The sort code IS numeric, but the label is alphanumeric - and doesn't match the sort code.


Also doing mids around the statement does NOT work. It eliminates some results, but not including the mids definitely is working for me.

Whee.

If you're in the States, have a happy 4th!
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,357
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top