1

I have these three tables as shown in this image below: SalesOrderTable, OrderAdjustmentTable, and TotalSalesTable.

enter image description here

SalesOrderTable

Each order number in the SalesOrderTable represent an order number for a product from the same invoice. It has A,B, or C if an invoice is made for more than one product, but not if it is only made for one product. E.g.: Order 1703 has two products, so it has A and B at the end of each order number. Order 1704 has an order for Apple only, so it doesn’t have any letter at its end.

OrderAdjustmentTable

Should there be any adjustments for each order number, they are inputted manually in the adjustment columns.

TotalSalesTable

In this table, all amount of total sales and adjustments for the same order number are totaled. So order for 1705 are combinations of 1705A, 1705B, 1705C.

Here are my current formulas, all of them produce error messages or don’t calculate correctly.

Order total amount column:

=SUMIF(SalesOrderTable[Order Number], LEFT(G4,LEN(SalesOrderTable[Order Number])-1),SalesOrderTable[Order Sales Amount])

Order Total Adjustment Column:

=sumifs(OrderAdjustmentTable[#All],OrderAdjustmentTable[Order Number],MATCH(B19,LEFT(SalesOrderTable[Order Number],LEN(SalesOrderTable[Order Number])-1), 0), "*Adjustment",OrderAdjustmentTable[#All])

I know it may have something to do with match and sumifs, but all the formulas I made led to error messages. Anybody can help me with what I did wrong with these formulas above, and how do I fix them? I am at my wits end here and will appreciate any advice given. Thanks a lot!

Edit:

What I want to achieve is to fill:

The order total amount column in TotalSalesTable with all orders that have the same order number, irrespective of their ABC. So Total amount for 1705 will be the sum total of order amount for 1705A, 1705B, 1705C.

For the order total adjustment, I want to have all the adjustments value for the order number column in TotalSalesTable from OrderAdjustmentTable, irrespective of their ABC. So total adjustments for 1705 in TotalSalesTable will be 1705B and 1705C.

3
  • Could you include the expected outcome numbers as well explaining how the adjustments feed in to calculating the final totals?
    – QHarr
    Oct 1, 2018 at 4:21
  • Hi again @QHarr! I added what I want to achieve in the edited question above. Hope that makes it clearer!
    – user71812
    Oct 1, 2018 at 6:09
  • Hi @QHarr, I posted a more detailed and specific breakdown of the question I asked above here stackoverflow.com/questions/52588636/…, should you still be interested in helping out :) thanks!
    – user71812
    Oct 1, 2018 at 9:59

2 Answers 2

1

As long as there are no orders that overlap with and without letters (for instance, the SalesOrderTable having records for 1703, 1703A, and 1703B), the following formula should work in cell C19, from where you can copy it down:

Order Total Amount:

=SUMIFS(SalesOrderTable[Order Sales Amount],SalesOrderTable[Order Number],$B19)+SUMIFS(SalesOrderTable[Order Sales Amount],SalesOrderTable[Order Number],$B19&"*")

This formula adds together the exact and approximate matches, but like I said if any orders both have and are lacking a letter something will likely get duplicated/double counted. You should also be able to replicate the formula for the Order Total Adjustment Column.

3
  • Hi @M. Wise, thanks for answering. I tried your code, it works for Total Amount alright, but could you clarify what this means, please? "....but like I said if any orders both have and are lacking a letter something will likely get duplicated/double counted. "
    – user71812
    Oct 1, 2018 at 6:15
  • Sure. Say for example there are 3 records for 1703: one for 1703A for the amount of $200, one for 1703B for the amount of $300, and one total 1703 record for the amount of $500. If that were to ever happen, the formula would show $1000 rather than $500.
    – M. Wise
    Oct 1, 2018 at 14:33
  • Thanks for the clarification! Your solution works for Total Order Column, but I may have to use another solution for the total adjustment. But still, thanks for the solution!
    – user71812
    Oct 2, 2018 at 2:25
1

In messing around with this for a second, putting LEFT in SUMIF seems to cause issues (at least on Mac).

I'd recommend calculating Order Number without the letters in a separate column first. LEFT returns a character string so I had to wrap it in VALUE so that SUMIF will match. Since all of yours are four digits, I just used VALUE(LEFT([@[Order Number]],4))

Then it's just standard SUMIF notation:

=SUMIF(Table1[Base Num],[@[Order Number]],Table1[Order Sales Amount])

Example: https://www.dropbox.com/s/yj6ktl14jqglxsm/Example.xlsx?dl=0

There are various ways you could get the order number, but you have to be careful with your example:

LEFT(G4,LEN(SalesOrderTable[Order Number])-1) because this will work correctly for 1703A and 12990B, but will drop a number from 1701.

EDIT: This is one way to get order number if your number of digits varies: =IFERROR(VALUE(A2),VALUE(LEFT(A2,LEN(A2)-1)))

This says, "if VALUE(A2) returns an error (meaning it has a letter in it), remove the last character, otherwise, use VALUE(A2) since it's already a number."

4
  • 1
    I have had this before when using left() to return a number. My solution was to multiply by 1 ie =LEFT(A2,LEN(A2)-1))*1
    – Solar Mike
    Oct 1, 2018 at 6:24
  • @Mako212, that works for a cell, but how do I use it in this case, since my formula that incorporates yours get me an error message? '=MATCH(B19,IFERROR(VALUE(SalesOrderTable[Order Number]),VALUE(LEFT(SalesOrderTable[Order Number],LEN(SalesOrderTable[Order Number])-1))),0)'
    – user71812
    Oct 1, 2018 at 6:31
  • 1
    I would just add another column to your adjustment table that equals the sum of the three adjustment columns, then it will work the same way as the order table does.
    – Mako212
    Oct 1, 2018 at 19:48
  • Yes, that may work like that. I will see whether I can apply that to my problem. Thanks Mako!
    – user71812
    Oct 2, 2018 at 2:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.