+ Reply to Thread
Results 1 to 21 of 21

Adding a category to each product based on the groups title

  1. #1
    Forum Contributor
    Join Date
    04-25-2011
    Location
    Donegal, Ireland
    MS-Off Ver
    Excel 2013
    Posts
    133

    Adding a category to each product based on the groups title

    Hi, In the sample sheet attached each group of products are defined by a Title, Header Row and then the list of products.

    Not sure if this is possible but what i'd like to do is add a Category and Sub Category to Col D & E respectively for each product in the list for each group based on the groups title.

    eg.
    Group 1 Title 'Personal Computers - Computer Desktop' Col D would be 'Computers' & Col E 'Desktops'
    Group 2 Title 'Personal Computers - Computer Towers' Col D would be 'Computers' & Col E 'Tower PC's'
    Group 3 Title 'Personal Computers - All In One (AIO) Computers' Col D would be 'AIO PC's'

    and so on so that every product has a Category and Sub-Category that i could filter a lot easier.

    Any help would be immensely appreciated guys

    Regards
    John
    Attached Files Attached Files

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

    Re: Adding a category to each product based on the groups title

    This can be done with PowerQuery. Here's the M code:

    Please Login or Register  to view this content.
    Workbook attached - let me know if you woudl like to learn how to do it.
    Attached Files Attached Files
    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. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Contributor
    Join Date
    04-25-2011
    Location
    Donegal, Ireland
    MS-Off Ver
    Excel 2013
    Posts
    133

    Re: Adding a category to each product based on the groups title

    AliGW, That's absolutely exactly what i was looking, incredible.

    Can you tell me how to use it exactly

    Many many thanks

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

    Re: Adding a category to each product based on the groups title

    Yes, of course. Just give me a few minutes.

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

    Re: Adding a category to each product based on the groups title

    OK - here's what you need to do:

    1. In the original workbook (not my copy) select the whole of your source table (B1 to K377).
    2. With this range selected, go to the Data ribbon and click on From Table/Range in the Get & Transform area of the ribbon (on the left). This will load the table into PowerQuery.
    3. In the PQ editor that is now open, click on Advanced Editor in the ribbon (near the left).
    4. In the dialog that opens, replace all the code that appears with the code that I gave you above, then click on Done (bottom right).
    5. Finally, click on Close & Load at the far left of the PQ ribbon.

    All you need to do now is remember to refresh the table when changes are made to the source table (Refresh on the Data ribbon). This can be automated by setting auto-refresh in the query properties. To access the query properties, click Queries & Connections on the Data ribbon, then right-click the query in the pane that appears to the right and choose Properties.

    If you just want to use this as a one-off to get your data into a shape you are happy with going forward, then there is no need to worry about refreshing the data.

    You can step through the stages set up in the query to see what was done to reshape the data.

  6. #6
    Forum Contributor
    Join Date
    04-25-2011
    Location
    Donegal, Ireland
    MS-Off Ver
    Excel 2013
    Posts
    133

    Re: Adding a category to each product based on the groups title

    Hi, When i paste the code I get this error when i select done,

    Expression.Error: The column 'Personal Computers - Computer Desktop' of the table wasn't found.
    Details:
    Personal Computers - Computer Desktop

    Any thoughts

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

    Re: Adding a category to each product based on the groups title

    Well, yes - the workbook you are using is not the same as the one you shared here.

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

    Re: Adding a category to each product based on the groups title

    Does the M code work if you change cell B1 to 'Personal Computers - Computer Desktop' before loading the table into PQ? If not, then the workbook is significantly different to the one I created the M code with.

  9. #9
    Forum Contributor
    Join Date
    04-25-2011
    Location
    Donegal, Ireland
    MS-Off Ver
    Excel 2013
    Posts
    133

    Re: Adding a category to each product based on the groups title

    Hi, I've attached the file that i have been using which i assumed was the one i attached previously.

    When i select B1 to K377 and select 'table has headers' i now get this error

    Expression.Error: The column 'Column10' of the table wasn't found.
    Details:
    Column10

    regards
    John
    Attached Files Attached Files

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

    Re: Adding a category to each product based on the groups title

    You should NOT select 'Table has headers'.

    I will have a look at the new file.

  11. #11
    Forum Contributor
    Join Date
    04-25-2011
    Location
    Donegal, Ireland
    MS-Off Ver
    Excel 2013
    Posts
    133

    Re: Adding a category to each product based on the groups title

    That was the problem, it works perfect

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

    Re: Adding a category to each product based on the groups title

    It works perfectly here.

    Things to check:

    1. You selected the correct range (starting at B1, NOT A1).
    2. You deselected 'My table has headers' )sorry - I should have mentioned this.
    3. You copied and pasted my code OVER the code in the advanced window, NOT after it.

  13. #13
    Forum Contributor
    Join Date
    04-25-2011
    Location
    Donegal, Ireland
    MS-Off Ver
    Excel 2013
    Posts
    133

    Re: Adding a category to each product based on the groups title

    That's so powerful, thank you sooooo much AliGW and my apologies for the inconvenience.

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

    Re: Adding a category to each product based on the groups title

    Glad to hear it's working.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

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

    Re: Adding a category to each product based on the groups title

    Once bitten with PQ, and you'll be smitten. It's really useful - I use it every day in my job for data transformation (normalisation).

  16. #16
    Forum Contributor
    Join Date
    04-25-2011
    Location
    Donegal, Ireland
    MS-Off Ver
    Excel 2013
    Posts
    133

    Re: Adding a category to each product based on the groups title

    I can see why, it's incredible. Have a great Sunday and thank you once again

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

    Re: Adding a category to each product based on the groups title

    You, too. Sláinte!

  18. #18
    Forum Contributor
    Join Date
    04-25-2011
    Location
    Donegal, Ireland
    MS-Off Ver
    Excel 2013
    Posts
    133

    Re: Adding a category to each product based on the groups title

    Haha, Sláinte to you also, bit of the Cailín about ya

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

    Re: Adding a category to each product based on the groups title

    I have no Irish ancestry according to my My Heritage DNA results: quite a lot of Scandinavian, though. Like my Viking ancestors, I'm a marauder: in my case, it's in the hunt of all things linguistic.

  20. #20
    Forum Contributor
    Join Date
    04-25-2011
    Location
    Donegal, Ireland
    MS-Off Ver
    Excel 2013
    Posts
    133

    Re: Adding a category to each product based on the groups title

    Hi AliGW, apologies for bothering you again but i was just wondering if you would know a simple way to output PQ results to a .csv file

    Regards
    John

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

    Re: Adding a category to each product based on the groups title

    In what way? You can save any Excel file to .csv.

+ 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. Formula to use a title and sub title to calculate product price
    By kadawncg in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-17-2018, 02:06 AM
  2. Replies: 8
    Last Post: 09-06-2017, 12:47 PM
  3. [SOLVED] Adding missing title based on what text begins with
    By JohnnyBoyxxx in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-21-2016, 06:34 PM
  4. What can i use to display a category title based on a cells value?
    By smithjon in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 04-23-2013, 07:35 AM
  5. Produce Product list by product category
    By barnowl in forum Excel General
    Replies: 2
    Last Post: 01-03-2013, 05:57 PM
  6. [SOLVED] Help with adding time based on category and more.
    By swmwshrk in forum Excel General
    Replies: 11
    Last Post: 07-07-2012, 01:55 AM
  7. how to generate report based on adding costs of particular category
    By hoser in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 12-20-2007, 06:58 PM

Tags for this Thread

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