Help With a Query That Has Repeated Rows

Jamsandwich

New Member
Joined
Sep 25, 2014
Messages
44
Hey guys,

Sorry about the title, but I was struggling a bit...

I'll try to explain my problem here -

I have 3 tables: People, Projects & Functions. They have the following layout -

People
Name (Key)Contract Hrs
Steve37
Bill37
John37
Sue37
Andy37

<tbody>
</tbody>

Projects
Number (Key)TitleLead
1ApplesPeter
2BananasPeter
3CherriesJohn
4DragonfruitErin
5ElderberriesErin

<tbody>
</tbody>
This table isn't so important for the question but adds background.

Functions
ID (Key)Project #PersonHrs Required
11Steve1
21Sue3
31Bill2
42Bill2
53Steve2
64Sue1
74John2
85Steve2
95John2
105Andy5

<tbody>
</tbody>
The tables have a bit more than this, but we have enough here. So I am trying to put together a report which shows all of the details of each person and also has a text box connected to each person which shows the amount of hours they have available (Contract Hrs - Sum of Hrs Required).

To do this I have created queries. The first is simple: It gives me the sum of each person's Hrs required, grouped by person. This has the extra fields 'Person' (from function table) and 'SumofHrsRequired'. This query works fine.

The second query is where I am struggling. I created it and it appeared to work at first.

FieldPersonContract HoursSumofHrsRequiredHrsAvailable
TableQuery1PeopleQuery1
TotalGroupByGroupByGroupByGroupBy

<tbody>
</tbody>

HrsAvailable is - [Peple]![ContractHrs]-[Query1]![SumofHrsRequired]

Now, this appears to work when I create the Textbox on the report with a DLookup. The problem occurs when I change values in the 'Contract Hrs' field for individual people.

So if I change Steve to 35hrs and Sue to 30 hrs (for example), my query returns something like this -

PersonContract HrsSumofHrsHrsAvailable
Steve30525
Steve35530
Steve37532
Bill30426
Bill35431
Bill37433
John30426
John35431
John37433
Sue30426
Sue35431
Sue37433
Andy30525
Andy35530
Andy37532

<tbody>
</tbody>

This makes the value on my report come out wrong. I think it just goes with the first row for each person. Clearly, I've screwed up on my query but I don't know how to fix it.

Could somebody help me fix this?
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Oh man, I've managed to sort this out. Panic over, I think.

I think the problem was that I was querying both the first query and the 'People' table.

So now I have added a Contract Hrs field to the first query. This means that for the 2nd query I only need to link it to the 1st (and I took the 'People' table out).

This appears to give me the values that I need.
 
Upvote 0

Forum statistics

Threads
1,221,810
Messages
6,162,108
Members
451,743
Latest member
matt3388

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