Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Vilmar is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Posts
    5

    Somar Com Critérios Diferentes Com Relacionamento

    Olá


    Preciso somar a quantidade das vendas que estão na tabela esquerda, porem com critérios diferentes para cada supervisor da tabela direita. Como fazer isso no Access?

    Excel https://1drv.ms/x/s!AlT1IBz5Y6AO6wxQne28GNXemGct?e=OSXCTL


    Veja neste neste exemplo em Excel onde na tabela direita a fórmula SOMASES tem critérios diferentes para os supervisores:

    Click image for larger version. 

Name:	Sem título.jpg 
Views:	23 
Size:	109.8 KB 
ID:	47978


  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,444
    for the benefit of those who cannot read Portuguese.

    HelloI need to add the amount of sales that are in the left table, but with different criteria for each supervisor in the right table. How to do this in Access?Excel https://1drv.ms/x/s!AlT1IBz5Y6AO6wxQ...ct?e=OSXCTLSee this example in Excel where in the right table the SOMASES formula has different criteria for supervisors:



    @vilmar - please avail yourself of a translator such as google translate https://translate.google.com/
    por favor, aproveite um tradutor como o google translate https://translate.google.com/



  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,944
    How do you know which Vendas records go with with supervisor?
    If this data is in an Access database, then provide that file.
    Last edited by June7; 06-05-2022 at 02:25 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,568
    Hi Vilmar

    Unable to open the Excel File can you attach again?

    No se puede abrir el archivo de Excel, ¿puede adjuntarlo de nuevo?
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  5. #5
    Vilmar is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Posts
    5
    Obrigado pela resposta e pela dica

    Obrigado pela resposta e a dica

  6. #6
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,568
    Sorry but I don't speak the language. Luck with your project.
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  7. #7
    Vilmar is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Posts
    5
    Thanks for answering
    I can only find out which records are for each supervisor if I do a SUMIFS for each supervisor in Excel, something that is unfeasible due to the number of supervisors with different combinations.


    I believe the model would be something like access for users of a system.


    In this image below, it shows what the sum of the amount would look like for supervisor Ajani.Excel&Access.zip
    Attached Thumbnails Attached Thumbnails Sem título.jpg  

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,944
    Use Access query builder to construct SQL that joins tables on Regiao fields. Use LEFT JOIN or RIGHT JOIN, apply filter criteria on the Categoria field. Then click the Totals button on ribbon to add aggregation. Probably should not include Tipo, Loja, Meio fields.

    Doesn't really seem to be anything extraordinary about requirement.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,568
    Hi

    Your Relations ships between Regiao and Vendas would be on a PrimaryKey RegiaoID in Regiao table and Foreign Key RegiaoID in table Vendas.
    Attached Thumbnails Attached Thumbnails RI.JPG  
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  10. #10
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,568
    Your Data Input Form for Regiao and Vendas would look like the attached
    Attached Thumbnails Attached Thumbnails Data.JPG  
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  11. #11
    Vilmar is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Posts
    5
    It would almost be. The difficulty now is to create a query that brings the sum of the amount that is in the Sales table, but that meets all the combinations of the Criteria table


    Click image for larger version. 

Name:	Sem título.jpg 
Views:	19 
Size:	69.8 KB 
ID:	47987

  12. #12
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,444
    I think I now understand the principle of what you are trying to achieve and suspect you need to use what is called a cartesian query (no joins) and use criteria

    Something like

    Code:
    SELECT C.Supervisor, C.Relao, C.Tipo, C.LojaMelo, C.Categoria, sum(V.Qtd) as Total
    FROM Vendas V , Criteros C
    WHERE (V.Relao=C.Relao OR C.Relao is Null) AND (V.Tipo=C.Tipo OR C.Tipo is Null) AND (V.LojaMelo=C.V.LojaMelo OR C.LojaMelo is Null) AND (V.Categoria=C.Categoria OR C.Categoria is Null) 
    GROUP BY C.Supervisor, C.Relao, C.Tipo, C.LojaMelo, C.Categoria
    Edit:


    You have not explained the full business rules but for example assuming if Relao is not null, then you are to ignore the values in Tipo and LojaMelo then the query would be something like

    Code:
    SELECT C.Supervisor, C.Relao, C.Tipo, C.LojaMelo, C.Categoria, sum(V.Qtd) as Total
    FROM Vendas V , Criteros C
    WHERE (V.Relao=C.Relao OR C.Relao is Null) AND (V.Tipo=C.Tipo OR C.Tipo is Null OR C.Relao is NOT Null) AND (V.LojaMelo=C.V.LojaMelo OR C.LojaMelo is Null OR C.Relao is NOT Null) AND (V.Categoria=C.Categoria OR C.Categoria is Null)
    GROUP BY C.Supervisor, C.Relao, C.Tipo, C.LojaMelo, C.Categoria

  13. #13
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,568
    Hi

    Is there only 1 Supervisor for each Regiao ?
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  14. #14
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,568
    This query Design will give you the required output
    Attached Thumbnails Attached Thumbnails QryDesign.JPG   Totals.JPG  
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  15. #15
    Vilmar is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Posts
    5
    Hey guys!
    Thank you all for the tips, it helped me a lot.


    I couldn't find the button that marks the topic as completed.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums