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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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.


Follow on LinkedIn
@ 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!:
The Definitive Guide to Power Query (M)

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]
   )

Follow on LinkedIn
@ 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!:
The Definitive Guide to Power Query (M)

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.