Access Sum rows with duplicate fields

bassmandan

New Member
Joined
Jan 29, 2015
Messages
5
Hi guys,

I've searched high and low to find an answer to this but have so far been unsuccessful.

I have a query which shows skills against certain product categories. It is removing duplicates, but I still end up with a selection of duplicate rows. I would like to get rid of these by summing the values of each set of duplicates but am not sure how. I've posted a screen capture of a sample query (imgur: the simple image sharer) - in this example I would like to end up with three rows, one for storage showing 1,1,1, one for virtualisation showing 0,1,1 and one for wireless showing 1,2,2.

Can I do this using another query, or do I need to use some VBA?

Thanks for any help!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
SQL behind the query looks like this:

SELECT DISTINCT tblProducts.Category, IIf([tblSkillLevelsDesign].[DesignLevel]="None","0","1") AS Design, IIf([tblSkillLevelsInstallation].[InstallationLevel]="None","0","1") AS Installation, IIf([tblSkillLevelsSupport].[SupportLevel]="None","0","1") AS Support
FROM tblSkillLevelsInstallation INNER JOIN (tblSkillLevelsSupport INNER JOIN (tblSkillLevelsDesign INNER JOIN (tblProducts INNER JOIN (tblPeople INNER JOIN tblSkills ON tblPeople.ID = tblSkills.FullName) ON tblProducts.ID = tblSkills.Product) ON tblSkillLevelsDesign.ID = tblSkills.DesignLevel) ON tblSkillLevelsSupport.ID = tblSkills.SupportLevel) ON tblSkillLevelsInstallation.ID = tblSkills.InstallationLevel;
 
Upvote 0
Maybe:
<font face="Courier New" size="2">
<font color = "blue">SELECT</font> <font color = "maroon">category</font><font color = "silver">,</font>
<br/>       <font color = "#FF0080"><b>SUM</b></font><font color = "maroon">(</font><font color = "maroon">design</font><font color = "maroon">)</font>       <font color = "blue">AS</font> <font color = "maroon">Design</font><font color = "silver">,</font>
<br/>       <font color = "#FF0080"><b>SUM</b></font><font color = "maroon">(</font><font color = "maroon">installation</font><font color = "maroon">)</font> <font color = "blue">AS</font> <font color = "maroon">Installation</font><font color = "silver">,</font>
<br/>       <font color = "#FF0080"><b>SUM</b></font><font color = "maroon">(</font><font color = "maroon">support</font><font color = "maroon">)</font>      <font color = "blue">AS</font> <font color = "maroon">Support</font>
<br/><font color = "blue">FROM</font>   <font color = "maroon">(</font><font color = "blue">SELECT</font> <font color = "maroon">tblproducts</font><font color = "silver">.</font><font color = "maroon">category</font><font color = "silver">,</font>
<br/>               <font color = "#FF0080"><b>Iif</b></font><font color = "maroon">(</font><font color = "maroon">[tblskilllevelsdesign]</font><font color = "silver">.</font><font color = "maroon">[designlevel]</font> <font color = "silver">=</font> <font color = "maroon">"none"</font><font color = "silver">,</font> <font color = "black">0</font><font color = "silver">,</font> <font color = "black">1</font><font color = "maroon">)</font>             <font color = "blue">AS</font> <font color = "maroon">Design</font><font color = "silver">,</font>
<br/>               <font color = "#FF0080"><b>Iif</b></font><font color = "maroon">(</font><font color = "maroon">[tblskilllevelsinstallation]</font><font color = "silver">.</font><font color = "maroon">[installationlevel]</font> <font color = "silver">=</font> <font color = "maroon">"none"</font><font color = "silver">,</font> <font color = "black">0</font><font color = "silver">,</font> <font color = "black">1</font><font color = "maroon">)</font> <font color = "blue">AS</font> <font color = "maroon">Installation</font><font color = "silver">,</font>
<br/>               <font color = "#FF0080"><b>Iif</b></font><font color = "maroon">(</font><font color = "maroon">[tblskilllevelssupport]</font><font color = "silver">.</font><font color = "maroon">[supportlevel]</font> <font color = "silver">=</font> <font color = "maroon">"none"</font><font color = "silver">,</font> <font color = "maroon">"0"</font><font color = "silver">,</font> <font color = "maroon">"1"</font><font color = "maroon">)</font>       <font color = "blue">AS</font> <font color = "maroon">Support</font>
<br/>        <font color = "blue">FROM</font>   <font color = "maroon">tblskilllevelsinstallation</font>
<br/>               <font color = "blue">INNER</font> <font color = "blue">JOIN</font> <font color = "maroon">(</font><font color = "maroon">tblskilllevelssupport</font>
<br/>                           <font color = "blue">INNER</font> <font color = "blue">JOIN</font> <font color = "maroon">(</font><font color = "maroon">tblskilllevelsdesign</font>
<br/>                                       <font color = "blue">INNER</font> <font color = "blue">JOIN</font> <font color = "maroon">(</font><font color = "maroon">tblproducts</font>
<br/>                                                   <font color = "blue">INNER</font> <font color = "blue">JOIN</font> <font color = "maroon">(</font><font color = "maroon">tblpeople</font>
<br/>                                                               <font color = "blue">INNER</font> <font color = "blue">JOIN</font> <font color = "maroon">tblskills</font>
<br/>                                                                       <font color = "blue">ON</font> <font color = "maroon">tblpeople</font><font color = "silver">.</font><font color = "maroon">id</font> <font color = "silver">=</font> <font color = "maroon">tblskills</font><font color = "silver">.</font><font color = "maroon">fullname</font><font color = "maroon">)</font>
<br/>                                                           <font color = "blue">ON</font> <font color = "maroon">tblproducts</font><font color = "silver">.</font><font color = "maroon">id</font> <font color = "silver">=</font> <font color = "maroon">tblskills</font><font color = "silver">.</font><font color = "maroon">product</font><font color = "maroon">)</font>
<br/>                                               <font color = "blue">ON</font> <font color = "maroon">tblskilllevelsdesign</font><font color = "silver">.</font><font color = "maroon">id</font> <font color = "silver">=</font> <font color = "maroon">tblskills</font><font color = "silver">.</font><font color = "maroon">designlevel</font><font color = "maroon">)</font>
<br/>                                   <font color = "blue">ON</font> <font color = "maroon">tblskilllevelssupport</font><font color = "silver">.</font><font color = "maroon">id</font> <font color = "silver">=</font> <font color = "maroon">tblskills</font><font color = "silver">.</font><font color = "maroon">supportlevel</font><font color = "maroon">)</font>
<br/>                       <font color = "blue">ON</font> <font color = "maroon">tblskilllevelsinstallation</font><font color = "silver">.</font><font color = "maroon">id</font> <font color = "silver">=</font> <font color = "maroon">tblskills</font><font color = "silver">.</font><font color = "maroon">installationlevel</font><font color = "maroon">)</font> <font color = "blue">AS</font> <font color = "maroon">[Raw]</font>
<br/><font color = "blue">GROUP</font>  <font color = "blue">BY</font> <font color = "maroon">category</font> 
</font>



Syntax may be slightly off since I don't use access - the principle will be the same though
 
Upvote 0
Thanks Kyle. I get a circular reference error 'caused by alias Design in query definition's SELECT list'. If I change the aliases then I don't get the error, but the query doesn't work. Any chance you could give me a rough explanation of what the different sections of SQL are doing (I've no experience with SQL but I can pick that kind of thing up pretty well) and I can try and troubleshoot?
 
Upvote 0
Try removing the Aliases from the other most query (ie SUM(design) AS Design remove the As Design). Essentially it is just your query, but grouping by the category (so you only get one line) then summing each of the 1s in the rows. So you get one line per category with a sum of the 1s
 
Upvote 0
Kyle - that's absolutely fantastic, it works perfectly without 'As xxxxx'. Thank you so much for your help!

Dan
 
Upvote 0

Forum statistics

Threads
1,221,905
Messages
6,162,772
Members
451,786
Latest member
CALEB23

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