cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MSanchezz
Frequent Visitor

LOOKUP in SAME TABLE

Hi All,

 

I would like to ask assistance in the scenario below:

 

currently have a table with the first three columns, and I want to add a column for the Transaction Group.
         Rules:

         > If Item group is MB, get the first item group with same transaction no.
         > If item is not MB, get row item group.

Transaction NoItemItem GroupTransaction Group
11001ANAN
11002ANAN
11015MBAN
21004RRRR
21015MBRR
31001ANAN
31002ANAN
31015MBAN
31020RRRR

 

Thank you.

1 ACCEPTED SOLUTION

Hi Greg, this worked for my sample dataset. will check on the full dataset before accepting as solution. thank you.

View solution in original post

6 REPLIES 6
edhans
Super User
Super User

Is this what you want?

edhans_0-1632182113248.png

You said you wanted the "row item group" if Item Group wasn't MB, but I wasn't sure what that meant. I pulled the item group from the same row.

Code here:

Column = 
VAR varItemGroup = 'Table'[Item Group]
VAR varTransaction = 'Table'[Transaction No]
RETURN
    IF(
        varItemGroup = "MB",
        MINX(
            FILTER(
                'Table',
                'Table'[Transaction No] = varTransaction
            ),
            'Table'[Transaction Group]
        ),
        'Table'[Item Group]
    )

 

Note: This is a calculated column formula and must be entered as a New Column to work.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
MSanchezz
Frequent Visitor

Hi. noticed that you used the transaction group column in the formula. What i meant was that, I am trying to have the trans group column be the output.

 

Thank you.

Ahh.. DIdn't understand TransactionGroup was the expected result. Try this @MSanchezz

 

Column = 
VAR varItemGroup = 'Table'[Item Group]
VAR varItem = 'Table'[Item]
VAR varTransaction = 'Table'[Transaction No]
RETURN
    IF(
        varItemGroup = "MB",
        MINX(
            FILTER(
                'Table',
                'Table'[Transaction No] = varTransaction
                    && 'Table'[Item] < varItem
            ),
            'Table'[Item Group]
        ),
        'Table'[Item Group]
    )

edhans_2-1632185180126.png

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

@MSanchezz I think I got it correct, please check, I did not use Transaction Group in my formula.


@ me in replies or I'll lose your thread!!!
Check out my External Tool for Power BI Desktop! Microsoft Hates Greg's Quick Measures
YouTube Channel! Microsoft Hates Greg
Check out my latest book!

Greg_Deckler
Super User
Super User

@MSanchezz Maybe:

Transaction Group = 
  IF(
    "Item Group" = "MB",
        VAR __First = MINX(FILTER('Table',[Transaction]=EARLIER([Transaction])),[Item])
      RETURN
        MAXX(FILTER('Table',[Transaction]=EARLIER([Transaction]) && [Item]=__First),[Item Group]),
      [Item Group]
   )

@ me in replies or I'll lose your thread!!!
Check out my External Tool for Power BI Desktop! Microsoft Hates Greg's Quick Measures
YouTube Channel! Microsoft Hates Greg
Check out my latest book!

Hi Greg, this worked for my sample dataset. will check on the full dataset before accepting as solution. thank you.

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

November Power BI Update 768x460.png

Check it Out!

Click here to read more about the November 2021 Updates!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.