+ Reply to Thread
Results 1 to 12 of 12

POWERPIVOT lookup based on 2 columns/conditions

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

    POWERPIVOT lookup based on 2 columns/conditions

    Hello,

    I hope the tables below can give you an idea of what I'd like to accomplish.

    Basically, given 2 tables, the transaction table and lookup table, In POWERPIVOT, I'd like to create a column where in the 'Transaction Table', I can do a function where I can do a lookup and return the value from another table.

    So how can I go about doing it?

    Transaction Table
    GL Functional Area
    1 Z000
    1 Z001
    1 Z002
    1 Z003
    1 Z003
    1 Z004
    2 Z000
    2 Z001
    2 Z002
    2 Z003
    2 Z003
    2 Z004


    Lookup Table
    Group GL Functional Area
    Grocery Expense 1 Z000, Z001
    Restaurant Expense 1 Z002
    Entertainment Expense 1 Z003
    Other Expense 1 Z004
    Mortgage Expense 2 Z000, Z001
    Utilities Expense 2 Z002
    Interest Expense 2 Z003
    Amortization/Depreciation 2 Z004

    Desired Result in Transaction Table
    GL Functional Area Group
    1 Z000 Grocery Expense
    1 Z001 Grocery Expense
    1 Z002 Restaurant Expense
    1 Z003 Entertainment Expense
    1 Z003 Entertainment Expense
    1 Z004 Other Expense
    2 Z000 Mortgage Expense
    2 Z001 Mortgage Expense
    2 Z002 Utilities Expense
    2 Z003 Interest Expense
    2 Z003 Interest Expense
    2 Z004 Amortization/Depreciation

    Crosspost: http://www.excelguru.ca/forums/showt...y-relationship
    Last edited by dluhut; 05-31-2017 at 12:52 PM.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: POWERPIVOT lookup based on 2 columns/conditions

    Ideally, LU table should have relationship with Transaction table.

    Without it DAX becomes needlessly complex and/or impossible.

    In your example I'd recommend either doing Lookup in PowerQuery stage. Or restructuring your LU table like below.


    Lookup Table
    Group GL Functional Area
    Grocery Expense 1 Z000
    Grocery Expense 1 Z001
    Restaurant Expense 1 Z002
    Entertainment Expense 1 Z003
    Other Expense 1 Z004
    Grocery Expense 2 Z000
    Grocery Expense 2 Z001
    Utilities Expense 2 Z002
    Interest Expense 2 Z003
    Amortization/Depreciation 2 Z004

    You can then add calculated column to each table ([Key]) with formula...
    =[GL]&[Functional Area]

    Then add relationship on that column.

    Then in Transaction table add calculated column.
    =RELATED(Lookup[Group])
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

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

    Re: POWERPIVOT lookup based on 2 columns/conditions

    Hi CK76,

    Thanks for the reply!

    I get the concept that you've given to me, but to be honest, I thought of that too. The reason I can't do it the way that you've taught me is because I have hundreds of GL (close to a thousand) and tens of Functional Area (close to 50).

    So if I were to create a unique identifier of each GL and FA, not only that it'll take a huge amount of time maintaining this lookup table, but also, prone to human error as well.

    That's why I'm wondering if there's a way to do it in POWERPIVOT using DAX/query formula.

    PS: I don't have POWERQUERY installed, since it's office laptop. As well, tried asking IT to install it, but was not approved as it's not 'tested' and also need higher level approval.

  4. #4
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: POWERPIVOT lookup based on 2 columns/conditions

    text to column on column C

    After that make a table of that data => insert => table.

    After that CTRL + H find space => replace by leave blanc (on column D and further)
    After that run the attached macro.
    The result is on sheet Output

    See the attached file.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by oeldere; 05-31-2017 at 02:33 PM. Reason: Added": After that make a table of that data => insert => table.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

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

    Re: POWERPIVOT lookup based on 2 columns/conditions

    Thanks oeldere,

    But VBA doesn't do anything to PowerPivot.

    Besides, I had multiple tables that I had which are added to the 'Data Model'. In it, then I combined them with a unique table that I have created on my own to 'Append' (combining the tables into 1), which thus become that 'Transaction Table' that I had.

    Because it's approximately 2 million of rows, I can't 'export' it into the table/worksheet. Thus, that's the reason why I said that the macro won't work.

  6. #6
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: POWERPIVOT lookup based on 2 columns/conditions

    PS: I don't have POWERQUERY installed
    So I thought you where looking for another solution to solve your problem.

    Reading your reply I probably did not understand the request.

  7. #7
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: POWERPIVOT lookup based on 2 columns/conditions

    @dluhut

    Try following. LU = Lookup Table, Tran = Transaction Table

    DAX_CalculatedColumn
    Please Login or Register  to view this content.
    Though I really wouldn't recommend this approach.

  8. #8
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: POWERPIVOT lookup based on 2 columns/conditions

    Alway good to let us know you crosspost the item.

    https://www.mrexcel.com/forum/power-...ationship.html

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

    Re: POWERPIVOT lookup based on 2 columns/conditions

    Quote Originally Posted by CK76 View Post
    @dluhut

    Try following. LU = Lookup Table, Tran = Transaction Table

    DAX_CalculatedColumn
    Please Login or Register  to view this content.
    Though I really wouldn't recommend this approach.
    Thanks CK76!!! I tried to put it on a sample that's above and it works.

    However, when I try to put it onto my live data, it's giving me #ERROR value.

    When I click on the 'Show Error', it says, "Calculation error in column '2017sapbw'[]: A table of multiple values was supplied where a single value was expected."

    I checked on '2017sapbw'[GL Account] and '2017sapbw'[Functional Area] and they're all single value.

    So may I know what went wrong?

    PS: '2017sapbw' is the same as Tran in this case.

    PS2: Reps up to you

    Edit: I realized that it wasn't specifically the 'Trans' table that has duplicate values, but it was the LU table that has the duplicate values but different Group.
    Last edited by dluhut; 05-31-2017 at 07:16 PM.

  10. #10
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: POWERPIVOT lookup based on 2 columns/conditions

    You are welcome and thanks for the rep.

    I realized that it wasn't specifically the 'Trans' table that has duplicate values, but it was the LU table that has the duplicate values but different Group.
    Yes, in this instance what the error message means is that Multiple value was supplied to "'2017sapbw'[]" (from LU table) during calculation, resulting in error due to end result having more than single value.

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

    Re: POWERPIVOT lookup based on 2 columns/conditions

    CK76,

    Am wondering if there's a 'evaluate' function that I can use anywhere, or a trick on the DAX function, just like in Excel, where I can go the the 'Evaluate' icon, and step by step, I can see what the 'result' of the formula is doing.

    Reason I asked this is that I find it difficult to understand DAX.

    For example, in your above formula, I understand ONLY the LOOKUPVALUE function, but as for the FIRSTNONBLANK and VALUES function, I didn't get it at all. Tried googling and read but still don't exactly know what it's actually doing, not to mention the 'result' of it that gets assigned to the other functions.

  12. #12
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: POWERPIVOT lookup based on 2 columns/conditions

    Am wondering if there's a 'evaluate' function that I can use anywhere
    Not that I'm aware of.

    Understanding SQL statements will help in understanding DAX. But best way to learn is to find various problems found on forums which has been solved.
    First try to solve it without looking at the solution. Then compare your result with the one accepted/posted. I've learned it mostly through this method.

+ 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] Powerpivot Lookup Function
    By songgirl101 in forum Excel Formulas & Functions
    Replies: 20
    Last Post: 05-25-2016, 02:35 PM
  2. Replies: 4
    Last Post: 07-23-2015, 03:35 PM
  3. Replies: 2
    Last Post: 06-02-2014, 09:34 AM
  4. Dividing Two Columns in PowerPivot
    By [email protected] in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 05-09-2013, 09:53 AM
  5. Replies: 0
    Last Post: 11-20-2012, 05:34 AM
  6. Lookup 2 columns and return value based on another 2 columns
    By rlsublime in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-13-2012, 11:16 AM
  7. lookup based on two columns
    By DKerr in forum Excel General
    Replies: 1
    Last Post: 01-31-2007, 02:13 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