+ Reply to Thread
Results 1 to 13 of 13

substract a positive value besed on column header How?

  1. #1
    Registered User
    Join Date
    08-07-2018
    Location
    Estonia
    MS-Off Ver
    365
    Posts
    28

    substract a positive value besed on column header How?

    Hi,
    this is my first post here

    I am looking for help with the following.
    I have a table of products and they will have IN and OUT values based on orders (copied from elsewhere). The copied values are all positive, but actually IN is positive and OUT is negative.
    Product IN1 IN2 OUT1 OUT2
    A 200 100
    B 30 50 5
    C 50 35
    A 20 35
    More and more INs and OUTs will be added during the year. I have changed my source date to a TABLE so the cell names can be updated easily.

    I want my pivot table to have the sum of all INs and OUTs (say, for A), while treating OUT as negative.
    I could add a Calculated field with the formula In1+IN2-OUT1-OUT2, but then I will need to manually change the formula each time a new IN our OUT comes. I would love that when I add a new IN/OUT to the pivot table Value section, the SUM=IN-OUT for each row would update automatically.

    Theoretically, I have tried making a separate sheet that checks if the column name has OUT in it and then multiplies the value by -1 and getting the Pivot from there. But this involves having an extra page and manually increasing the size of the TABLE on the second page.

    Thank you all in advance for help.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: substract a positive value besed on column header How?

    Hi, welcome to the forum :0

    If you have already converted this a Structured Table, then, when you add new data, that formula should auto-populate for you?

    A quick formula to calc your sum would be...
    =SUMPRODUCT(--($A$15:$A$18="a")*(B15:C18-D15:E18))
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    08-07-2018
    Location
    Estonia
    MS-Off Ver
    365
    Posts
    28

    Re: substract a positive value besed on column header How?

    Thanks for your answer.

    Do you mean this should be added to each item in the source table (and not Pivot)? I can not convert Pivot to Table.
    Capture.JPG
    I would love to use Pivot table as then I can see all groups of items. Also, I assume the SUMPRODUCT needs a manual imput of all items (one formula for apples, one for water), right? As I have around 400 items already now, this will be complicated. In addition, the array you mentioned, apparently, need to be in arrays (is this the right word?) of all INs in sequence then all OUTs in sequence. I had hoped it is possible to keep them in the order they come in (e.g. based on dates).

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: substract a positive value besed on column header How?

    To best describe or illustrate your problem you would be better off attaching a dummy workbook. The workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    To attach a file to your post,
    click advanced (next to quick post),
    scroll down until you see "manage file",
    click that and select "add files" (top right corner).
    click "select files" find your file, click "open" click "upload" click 'done" bottom right. click "submit reply"

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.

  5. #5
    Registered User
    Join Date
    08-07-2018
    Location
    Estonia
    MS-Off Ver
    365
    Posts
    28

    Re: substract a positive value besed on column header How?

    I've attached what I am trying to get. Hope this helps.

    Should have done this at the beginning, sorry.
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,542

    Re: substract a positive value besed on column header How?

    In the screen shot it appears that some items (bread) have all values on a single row. If it is possible to continue that trend for all items then you could assign your pivot table (see sheet 1) to reference a helper range (rows 8:13) that could be populated using: =IF(LEFT(C$9,3)="out",-C3,C3)
    Let us know if you have any questions.
    Attached Files Attached Files
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  7. #7
    Valued Forum Contributor
    Join Date
    09-25-2015
    Location
    Nowy Tomysl, Poland
    MS-Off Ver
    2019, O365
    Posts
    398

    Re: substract a positive value besed on column header How?

    Try it can reorganize your data, it will be a bit easier.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    08-07-2018
    Location
    Estonia
    MS-Off Ver
    365
    Posts
    28

    Re: substract a positive value besed on column header How?

    I would like to thank everyone for helping, but this is still not what I am looking for. Either this is more complicated than I thought or my description was not good and now you are confused.. Sorry about that.

    Quote Originally Posted by JeteMc View Post
    In the screen shot it appears that some items (bread) have all values on a single row. If it is possible to continue that trend for all items then you could assign your pivot table (see sheet 1) to reference a helper range (rows 8:13) that could be populated using: =IF(LEFT(C$9,3)="out",-C3,C3)
    Let us know if you have any questions.
    Sadly, it is not possible to have all in a single row due to the large amount of data and it comes in codes. For user it would be easier to just keep copying BREAD from source data than searching if such code has already been ordered or not and write in the same row.

    Quote Originally Posted by stasinek View Post
    Try it can reorganize your data, it will be a bit easier.
    Thanks. Does this involve manually changing the OUT to negative?

    I am attaching a dummy file with the order data from the supplier - perhaps it will be more helpful. My end goal is to know how much we still have in stock. Sheet Orders - is the most raw data I get. Actually, I get each IN/OUT in separate e-mail and separate file (since they come on different dates). The "Data" sheet - I hoped it would make it easier....
    Attached Files Attached Files

  9. #9
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,907

    Re: substract a positive value besed on column header How?

    You could add a new column that totals each row, then just sum that in your pivot table?
    Rory

  10. #10
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,542

    Re: substract a positive value besed on column header How?

    I still feel a bit confused about the mechanism for producing the 'data' sheet based on the 'order' sheet, however perhaps this will help.
    On the order sheet column G is populated using: =IF(OR(LEFT(A2,2)="IN",LEFT(A2,3)="OUT"),LEFT(A2,SEARCH(" ",A2)-1),G1)
    Column D is populated using: =IF(A2<>"",A2,"")
    Column E is populated using: =IF(AND(G2="OUT",ISNUMBER(B2)),-B2,IF(ISNUMBER(B2),B2,""))
    Now instead of producing the 'data' sheet from columns A:B, columns D:E would be used and the 'OUT' values would be negative.
    Let us know if you have any questions.
    Attached Files Attached Files

  11. #11
    Valued Forum Contributor
    Join Date
    09-25-2015
    Location
    Nowy Tomysl, Poland
    MS-Off Ver
    2019, O365
    Posts
    398

    Re: substract a positive value besed on column header How?

    I see that you are using Ex 2016 and so you have Power Query.
    I would go in this direction. Add another data to the table created by you and on the "Data" tab click "Refresh everything" - it should work.
    When adding more data, remember to place them inside the table and not outside it.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    08-07-2018
    Location
    Estonia
    MS-Off Ver
    365
    Posts
    28

    Re: substract a positive value besed on column header How?

    I got around by reorganazing the sheet with data. Now it includes Orders horizontally, I do not have to do is copy the items from the order and as this is a structured table it will autopopulate all other rows. Including the conversion to negative.
    Sadly the Pivot does not show info "per order", but this can be filtered out.

    Thank you all for the ideas!

  13. #13
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: substract a positive value besed on column header How?

    happy to help

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. The last 11 Numbers in column / substract the smallest and biggest / do the average
    By titoine69 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-08-2015, 11:26 AM
  2. Replies: 1
    Last Post: 10-05-2013, 03:35 PM
  3. Substract column values with lowest number among them
    By shyam100379 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-22-2013, 02:06 AM
  4. [SOLVED] Copy ROW data besed on Cell Value
    By compgeek1979 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-23-2012, 07:15 PM
  5. [SOLVED] How to substract values in one column from another in every possible combination?
    By Alice_1989 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-03-2012, 04:38 PM
  6. Filtering records besed upon another sheet
    By hcnewhouse in forum Excel General
    Replies: 5
    Last Post: 02-28-2012, 07:28 AM
  7. [SOLVED] How do I substract numbers in range like this: Substract(a1..a10)
    By Paulo in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 11-17-2005, 12:50 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1