Share via

Access: Need to sum multiple fields in single row when related field are equal

Anonymous
2017-01-26T23:30:05+00:00

I need assistance building an expression similar to SUMIF.  I have 100+ rows with data in multiple fields that needs to be grouped (equal text) together for an overall amount on a single row. 

Query returns the following:

ltr 1 amt 1 ltr 2 amt 2 ltr 3 amt 3 ltr 4 amt 4
1 A 1 A 4 B 1
2 B 2 A 3 A 8 B 5
3 C 2 A 1 B 10

Results needed:

A B C
1 5 1
2 11 7
3 1 10 2

How is this achieved?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2017-01-27T00:01:21+00:00

    You're making this more complicated than it needs to be because your table design is not correct. You are "committing spreadsheet" - a venial sin for which the penance is studying normalization :-{)

    A better table design would be to recognize that you have a classic many to many relationship between whatever your main table's Entity is and Ltrs - each main table entity seems to have zero, one, two, three or four (or more?) Ltrs, and each Ltr may pertain to zero, one, two or many Rows. The proper design for this has THREE tables:

    ParentEntity

       EntityID (primary key)

       (other information about the entity as a thing in its own right)

    Letters

      Letter (text primary key, or more likely two fields, an Autonumber PK and a letter, since I suspect you've simplified the example)

    Amounts

       AmountID (autonumber primary key)

       EntityID (Long Integer, link to ParentEntity)

       Letter (or LetterID, link to Letters0

       Amt

    Then instead of summing several FIELDS you can use a Totals query (or, as suggested, a Crosstab) to sum several RECORDS.

    If I'm misinterpreting or oversimplifying your situation, please post the actual table structures; if that would reveal proprietary information, you can obfuscate the fieldnames - but don't distort it too much or we may not be able to understand the actual problem!

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2017-01-26T23:44:30+00:00

    Base upon your table structure you can use a 'Crosstab' query.

    If you need more assistance then post the SQL of the query you now have.

    Was this answer helpful?

    0 comments No comments