Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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

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!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
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!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

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

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors