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
Raj12
Helper II
Helper II

Lookup Value corresponding to matching ID from another table based on a condition in Power Bi

Create calculated column (in table2)with Lookup Value corresponding to matching ID from another table(Table 1) based on a condition where output value2 ,is lookup value with highest priroity from Table1 i.e.

1. Pause

2. No Pause

3. Other

 

Table 1
Id1  Value1
2002-10/01/2023  No Pause
2002-10/01/2023  Pause
2002-10/01/2023  Other
2103-10/01/2023  Pause
2103-10/01/2023  Pause
2105-10/01/2023  Other
2105-11/01/2023  No Pause
2106-11/01/2023  Other

 

 

Table 2
Id2  Value2
2002-10/01/2023  Pause
2103-10/01/2023  Pause
2105-10/01/2023  No Pause
2106-11/01/2023

  Other

 

I treid creating calculated column as:
Value2 = LOOKUPVALUE(Table1[Value1],Table1[Merged Copy],Table2[ID2])
This gives error as mutiple value was supplied

 

Another way gives only first value 
Value2 =
var xval= CALCULATE(FIRSTNONBLANK(Table1[Value1],TRUE()), FILTER(Table1,Table1[ID1]=Table2[ID2] ) )
return
if(xval="Pause" ,"Pause",IF(xval="No Pause","No Pause","Other"))

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@Raj12 Maybe:

Column = 
  VAR __ID = [Id2]
  VAR __Values = SELECTCOLUMNS( FILTER('Table 1', [Id1] = __ID), "__Value1", [Value1] )
  VAR __Result =
    SWITCH(TRUE(),
      "Pause" IN __Values, "Pause",
      "No Pause" IN __Values, "No Pause",
      "Other" IN __Values, "Other",
      BLANK()
    )
RETURN
  __Result

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...

View solution in original post

2 REPLIES 2
v-kongfanf-msft
Community Support
Community Support

Hi @Raj12 ,

 

The formula @Greg_Deckler  provided is worth looking at.

 

Also I created the following formula and was able to get the same results.

Value2 = 
VAR CurrentID = Table2[Id2]
VAR HighestPriorityValue =
    SELECTCOLUMNS (
        FILTER (
            Table1,
            Table1[Id1] = CurrentID
                && ( Table1[Value1] = "Pause"
                || Table1[Value1] = "No Pause" )
        ),
        "Value1", Table1[Value1]
    )
RETURN
    IF (
        COUNTROWS ( HighestPriorityValue ) > 0,
        MAXX ( HighestPriorityValue, [Value1] ),
        "Other"
    )

vkongfanfmsft_0-1710480079183.png

 

Best Regards,
Adamk Kong

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Greg_Deckler
Super User
Super User

@Raj12 Maybe:

Column = 
  VAR __ID = [Id2]
  VAR __Values = SELECTCOLUMNS( FILTER('Table 1', [Id1] = __ID), "__Value1", [Value1] )
  VAR __Result =
    SWITCH(TRUE(),
      "Pause" IN __Values, "Pause",
      "No Pause" IN __Values, "No Pause",
      "Other" IN __Values, "Other",
      BLANK()
    )
RETURN
  __Result

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...

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.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.