Query to Group Like Values in One Column, Pick 1st Value in Other Columns Where Values Are Different

zgadson

Board Regular
Joined
Jul 16, 2015
Messages
68
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello,

Could use some help. I have a scenario where I need to group by a column where values are the same, then other columns need to choose the 1st value.

Basically, I need to group by MAAISL and MAASLOT (which make up my Location column on my sheet), then for any duplicates it finds in that column, I need the ITDSC1 field to return what would be the 1st value. I have 99% of the code already, but the problem is that when I exclude ITDSC1 from the Group by element of my SQL, it returns an error.

Here's my code:
SQL:
SELECT

CONCAT(CONCAT(LTRIM(RTRIM(MAAISL)), '_'),LTRIM(RTRIM(MASLOT))) AS LOCATION,


CEILING(LTRIM(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(MASLOT, 'A', ''), 'B', ''), 'C', ''), 'D', ''), 'E', ''), 'F', ''), 'G', ''), 'H', ''), 'I', ''), 'J', ''), 'K', ''))) AS "SLOT.NUM",

LTRIM(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(MASLOT, '0', ''), '1', ''), '2', ''), '3', ''), '4', ''), '5', ''), '6', ''), '7', ''), '8', ''), '9', ''))  AS "SLOT.LVL",

LTRIM(MAAISL) AS "AISLE",
CEIL(LTRIM(MADEPT)) AS "SLOT.DEPTH",
CEILING(LCSTOR) AS "STR.NUM",
RTRIM(LTRIM(STNAME)) AS "STR.NAME",
LTRIM(ITDSC1) AS "ITM.DESC",
LTRIM(LCITEM) AS "ITM.CODE",
LTRIM(ITPDCD) AS "ITM.GRP",
CEILING(ITINDP) AS "ITM.DPTH",
CEILING(ITINWD) AS "ITM.WDTH",
CEILING(ITINHI) AS "ITM.HGHT",
MAX(ITPALH) AS "PLT.STK.HGHT",

SUM(CASE WHEN ITUNQ3 = ' ' THEN CEIL(QTY/ITUNQ2) ELSE CEIL((QTY/ITUNQ2)/ITUNQ3) END) AS "PLT.QTY"

FROM LOCXSTORER
WHERE MAWHSE = '  2'
GROUP BY MAWHSE, MAAISL, MASLOT, LCSTOR, STNAME, ITPDCD, MADEPT,ITINDP,ITINWD,ITINHI
ORDER BY MAAISL ASC

As always, any help would be greatly appreciated.

Thanks!
Zach
 

Attachments

  • Untitled.png
    Untitled.png
    14.9 KB · Views: 8

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Really wish there was an option to delete posts. Figured this out by using MAX to filter out fields I don't want to group by.
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

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