+ Reply to Thread
Results 1 to 28 of 28

Power Query to Extract Data based on multiple criteria

  1. #1
    Forum Contributor
    Join Date
    07-14-2014
    Location
    New City, NY
    MS-Off Ver
    2016
    Posts
    181

    Power Query to Extract Data based on multiple criteria

    Hello, wondering if someone can help me with this:

    The attached file has 4 tabs. The first tab is the comprehensive source data called SAP CY, the second tab is the P&L tab which extracts data from the first tab (SAP CY) using a sumif function. The third tab is a product P&L tab which is pulling data from the tab next to it called SAP HEM (which is a data extract from SAP)

    Similar to the P&L tab (2nd tab) i want the Product P&L tab to pull data from the SAP CY tab rather than the SAP HEM tab.

    Is there a way for power query in Excel 2016 to do this. The idea is to automate it for each month where we only need to update the SAP CY tab and the rest of the tabs update automatically?

    Thanks,

    Forgot to mention that there are only 4 products and the HEM product is 30 in the Brand Column. Thanks
    Attached Files Attached Files
    Last edited by Philipsfn; 01-11-2018 at 09:36 AM. Reason: Additional Info

  2. #2
    Forum Contributor
    Join Date
    07-14-2014
    Location
    New City, NY
    MS-Off Ver
    2016
    Posts
    181

    Re: Power Query to Extract Data based on multiple criteria

    Hello, would someone be able to help me with this? Thanks

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,916

    Re: Power Query to Extract Data based on multiple criteria

    There is no Power Query option in Excel 2007 - is your profile up-to-date?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  4. #4
    Forum Contributor
    Join Date
    07-14-2014
    Location
    New City, NY
    MS-Off Ver
    2016
    Posts
    181

    Re: Power Query to Extract Data based on multiple criteria

    I am on Excel 2016. What do i need to update? Thanks

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,916

    Re: Power Query to Extract Data based on multiple criteria

    Go to Settings (top right) and then Edit Profile (on the left).

  6. #6
    Forum Contributor
    Join Date
    07-14-2014
    Location
    New City, NY
    MS-Off Ver
    2016
    Posts
    181

    Re: Power Query to Extract Data based on multiple criteria

    Thank you so much!! Really appreciate your patience and help . Just updated it. Thanks

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,916

    Re: Power Query to Extract Data based on multiple criteria

    Thanks. I hope someone will answer soon. I am currently learning PQ, but am not yet in a position to advise on your query, although I suspect it can be done easily enough.

  8. #8
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Re: Power Query to Extract Data based on multiple criteria

    I don't know what you're to accomplished here, and I'm not an expert either.

    From what you're trying to accomplished, I'd say that PowerPivot is the way to do it.

    I'd use PowerQuery to make my data into tabular form, and from there, I'd then import it to the data model, and using DAX, I'd then create the P&L.

  9. #9
    Forum Contributor
    Join Date
    07-14-2014
    Location
    New City, NY
    MS-Off Ver
    2016
    Posts
    181

    Re: Power Query to Extract Data based on multiple criteria

    Thank you for your honest response. I appreciate that. Are you good with Macro's? I was thinking this can be done with a Macro as well if no one can help me? Thanks

  10. #10
    Forum Contributor
    Join Date
    07-14-2014
    Location
    New City, NY
    MS-Off Ver
    2016
    Posts
    181

    Re: Power Query to Extract Data based on multiple criteria

    I know how to use a normal pivot table but not sure about power pivot. Thanks

  11. #11
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Re: Power Query to Extract Data based on multiple criteria

    Although not an expert, I do know macro.

    But doesn't matter if you want it to be formula or macro, you'd need to give a sample of how the 'original' is and the 'desired result'.

    From the uploaded file that you had, I see that, there's formula that's still looking outside of the current workbook.

  12. #12
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Re: Power Query to Extract Data based on multiple criteria

    Attached is a snapshot of the work that I've done with PowerPivot for P&L
    Attached Images Attached Images

  13. #13
    Forum Contributor
    Join Date
    07-14-2014
    Location
    New City, NY
    MS-Off Ver
    2016
    Posts
    181

    Re: Power Query to Extract Data based on multiple criteria

    This should work for me too. In the attachment that i had posted, SAP CY is the data dump from SAP . We want to be able to populate the HEM P&L tab using two criteria to look up values from the SAP CY tab namely the Brand and P&L coding from the SAP CY tab. So if the Brand is "30" and the P&L coding is say "3" then pull in gross sales, if the brand is 30 and the P&L coding is "5" then pull in rebates and free goods. Currently i am using a sum if function but would like to automate this so that the only thing i need to do is to dump data into the SAP CY tab. Let me know if anything that i tried to explain is not clear. Thanks

  14. #14
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Re: Power Query to Extract Data based on multiple criteria

    Hi Philipsfn,

    Doing with PowerPivot, although in the very beginning is very cumbersome (especially DAX), but the end result is very rewarding, as like you wanted, you just have to update the SAP CY and like pivot table, when you refresh, all the new data is 'populated'.

    But since it takes a tremendous amount of work and to get to know your data, structure, calculation, what you want users to see etc, it's very difficult to do.

    Formula and/or macro could do what you wanted to accomplished, the only downside would be if there's "new data" that's not captured in the P&L, then it'll be very difficult to know, unless you have a check in place to ensure that the amount that's shown in the P&L is indeed the same as the data pull from SAP.

    Again, like I've mentioned in my previous reply, I saw formula that's looking on other workbook. So in order to incorporate formula and/or macro, one needs to know if the workbook name will always change every month etc.

    I've also read what you've wrote which I quote "... ... populate the HEM P&L tab using two criteria to look up values from the SAP CY tab namely the Brand and P&L coding from the SAP CY tab. So if the Brand is "30" and the P&L coding is say "3" then pull in gross sales, if the brand is 30 and the P&L coding is "5" then pull in rebates and free goods ... ..."

    When I look at your attached file, in the HEM P&L tab, I don't see a formula that look on 'SAP CY' tab, instead it's looking at an external workbook.

    Also, when I looked at 'SAP CY' tab, for Brand "30", I have many P&L codes associated to Brand "30"...but I don't see P&L coding of 3 or 5

  15. #15
    Forum Contributor
    Join Date
    07-14-2014
    Location
    New City, NY
    MS-Off Ver
    2016
    Posts
    181

    Re: Power Query to Extract Data based on multiple criteria

    Hi Dluhut,

    The tabs will have the same name each month. The only thing that will change is the data in the SAP CY tab. If you filter on columns C & D which is the brand and P&L , filer on Brand 30 and bring up P&L of 003 you will see that is the gross sales number which ties back to what is on the HEM P&L Tab. You are correct that this tab is populated by another tab which is basically the same SAP CY data except the person working on this file filtered it to show only HEM product Data. Keep in mind there are about 4 separate products, and for purppose of illustration i only showed here one product. We want to be able to create a P&L tab for each product using the SAP CY tab which is the master data. Hope this clarify's it a little better. If not clear, please do let me know. Thanks again for your time with this.

  16. #16
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Re: Power Query to Extract Data based on multiple criteria

    If that's the case, SUMIFS formula does work in this case.

    in 'HEM P&L' tab, in cell C8, paste the formula below

    Please Login or Register  to view this content.
    Also, you need to identify, what brand goes to which 'Net Sales categories'...i.e. You've mentioned that 'Gross Sales' and 'Rebates and free goods' are Brand 30

    You just need to ensure that whenever a user copy and paste the date to 'SAP CY', the column name should be the same, especially those that you're of interest, such as 'Brand' is on column C, 'P&L' is on column D and 'Net Month' is on column E etc.

  17. #17
    Forum Contributor
    Join Date
    07-14-2014
    Location
    New City, NY
    MS-Off Ver
    2016
    Posts
    181

    Re: Power Query to Extract Data based on multiple criteria

    Thanks, Can we build a macro to do this? I wanted to make this as foolproof as possible . Currently i am using this exact formula to update this. Someone suggested Power Query that is why i asked. Can we use a power pivot to accomplish this? Thanks

  18. #18
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Power Query to Extract Data based on multiple criteria

    I read but I need to ask question
    you want all columns from SAP CY filtered by C (30) & D (003) on another sheet via PowerQuery?
    or I misunderstood...

  19. #19
    Forum Contributor
    Join Date
    07-14-2014
    Location
    New City, NY
    MS-Off Ver
    2016
    Posts
    181

    Re: Power Query to Extract Data based on multiple criteria

    Correct. Brand 30 could have multiple P&L items . I just used 30 & 003 for illustration purposes. There are 4 brands in all. 30, 35,25 & 27 each of these have multiple P&L codes. We want to be able to extract for each brand these multiple P&L codes. Thanks

  20. #20
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Power Query to Extract Data based on multiple criteria

    But you want all-in-one or four different tables
    1st for Brand 30
    2nd for Brand 35
    3rd for Brand 25
    4th for Brand 27

    and ALL columns or only C & D ?

    25,27,30,35 are all brands so filter is not necessary
    Last edited by sandy666; 01-15-2018 at 05:49 PM.

  21. #21
    Forum Contributor
    Join Date
    07-14-2014
    Location
    New City, NY
    MS-Off Ver
    2016
    Posts
    181

    Re: Power Query to Extract Data based on multiple criteria

    Thanks again. 4 different tables with all columns. Is this possible? so on one tab it will be brand 30 and all the P&L combinations, on the second tab , brand 35 and all P&L combinations etc. Thanks

  22. #22
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Power Query to Extract Data based on multiple criteria

    So you can do that by yourself very simply.
    • remove filtering from SAP CY
    • Use Ctrl+T (it will change it from range to table)
    • Go to Data - From table
    • Close&Load as connection
    • Data - Show Queries
    • in new PowerQuery window (Queries) right click on Table1 and click Reference
    • Do that four times because you've 4 Brands
    • edit and filter 1st Reference col Brand by 25 - close & load as connection
    • edit and filter 2nd reference col Brand by 27 - close & load as connection
    • edit and filter 3rd reference col Brand by 30 - close & load as connection
    • edit and filter 4th reference col Brand by 35 - close & load as connection


    (in PowerQuery columns has headers not letters like in the sheet)

    • new sheet
    • Data - Show Queries
    • select cell where your table should start
    • Right click on 1st reference and load to
    • select Table and existing worksheet/cell - load


    and again new sheet.... and so on four times

    ask more questions if needed

    see attached file
    Attached Files Attached Files
    Last edited by sandy666; 01-15-2018 at 06:33 PM.

  23. #23
    Forum Contributor
    Join Date
    07-14-2014
    Location
    New City, NY
    MS-Off Ver
    2016
    Posts
    181

    Re: Power Query to Extract Data based on multiple criteria

    Thank you so much for your help with this. I didnt realize Power Query had so many steps to go through. Even after extracting the data i would still have to use SUMIFS function to get it into the P&L tab. Is there another way to get data from SAP CY to the product P&L tabs rather quickly? Thanks

  24. #24
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,916

    Re: Power Query to Extract Data based on multiple criteria

    Once you have set PQ up, you can refresh the data any time you like, so you only have to go through those steps once.

  25. #25
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Re: Power Query to Extract Data based on multiple criteria

    If that's what you want, can't we not use a regular pivot table to do this?

    And then from there, just use a 'GETPIVOTDATA' formula?

  26. #26
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Power Query to Extract Data based on multiple criteria

    If that takes care of your original question, & to say Thanks, please click on Add Reputtion (bottom left corner of the post of the person(s) who helped you)
    then select Thread Tools from the menu (top right corner of your thread) and mark this thread as SOLVED.
    If you did it already - ignore it.
    Thank you.

  27. #27
    Forum Contributor
    Join Date
    07-14-2014
    Location
    New City, NY
    MS-Off Ver
    2016
    Posts
    181

    Re: Power Query to Extract Data based on multiple criteria

    Thank you. I will play around with this and let you know how effective it is. The step by step instruction was very helpful.

  28. #28
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Power Query to Extract Data based on multiple criteria

    You are welcome and thanks for the feedback

+ 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. [SOLVED] Power Query: Extract data from table after other rows are filtered
    By JimDandy in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 08-25-2017, 02:10 AM
  2. [SOLVED] extract multiple data based on criteria
    By wodo5 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-11-2017, 12:05 AM
  3. Extract Unique data based on multiple criteria
    By ajaypal.sp in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-27-2016, 01:13 PM
  4. [SOLVED] Extract data based on multiple criteria
    By Thanks4helping in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 06-21-2016, 04:31 PM
  5. How to extract data based on multiple criteria
    By NS4Excel in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-11-2015, 07:56 PM
  6. Extract Data Based on Multiple Criteria
    By trevaaaaaaa in forum Excel General
    Replies: 2
    Last Post: 03-14-2012, 11:42 AM
  7. Replies: 2
    Last Post: 03-23-2011, 06:19 PM

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