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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kkalyanrr
Helper V
Helper V

Looking up values

Hello Team,

 

I'm using lookupvalue function to retrieve a value from a different table, and my requirement is little different.

Please help me with this.

 

 

Source TableSource TableMain TableMain TableExpected ResultExpected Result

2 ACCEPTED SOLUTIONS

Hi @kkalyanrr

 

Try this solution

 

In your main Table, add a calculated column

 

Randnumber =
RANDBETWEEN ( 1, 10000 )

Now you can do that  LookUp using this Calculated Column

Sales =
VAR MaxNumber =
    CALCULATE (
        MAX ( MainTable[Randnumber] ),
        ALLEXCEPT ( MainTable, MainTable[ID] )
    )
RETURN
    IF (
        MainTable[Randnumber] = MaxNumber,
        LOOKUPVALUE ( SourceTable[Sales], SourceTable[Id], MainTable[ID] )
    )

Regards
Zubair

Please try my custom visuals

View solution in original post

6 REPLIES 6
v-huizhn-msft
Employee
Employee

Hi @kkalyanrr,

I reproduce your scanrio and get expected result, please follow steps below.

1. Add a index column in Main table by clicking add index column from 1 in Query Editor->Apply&close. Create a relationship between Source and Main tables.

1.PNG  5.PNG

2. Create a calculated column using the formula.

Column =
IF (
    Main[Index] = CALCULATE ( MIN ( Main[Index] ), ALLEXCEPT ( Main, Main[Id] ) ),
    LOOKUPVALUE ( Source[Sales], Source[Id], Main[Id] ),
    BLANK ()
)


2.PNG

3. Create a new table only including [Id] and [Sales] columns. Click New Table under Modeling on Home page, type the formula and get expected result.

3.png

Best Regards,
Angelia

@v-huizhn-msft

 

Thanks for the reply.

 

My source table is an Union table , so I cannot add an Index Column. Is there any other way to achieve this result.

 

Thanks,

Kalyan..

Hi @kkalyanrr,

As I tested, you can still create a calculated column in Power BI desktop using RANDBETWEEN function to identify each row, and use the DAX to get expected result. The DAX formula still can be used in Power BI desktop.

Best Regards,
Angelia


Hi @kkalyanrr,

Got it, you can not edit the table because your resouce table is created by DAX. But you have to add index column to identity each row, if you can add index column in the original table used to create your Union table? 

Best Regards,
Angelia


Hi @kkalyanrr

 

Try this solution

 

In your main Table, add a calculated column

 

Randnumber =
RANDBETWEEN ( 1, 10000 )

Now you can do that  LookUp using this Calculated Column

Sales =
VAR MaxNumber =
    CALCULATE (
        MAX ( MainTable[Randnumber] ),
        ALLEXCEPT ( MainTable, MainTable[ID] )
    )
RETURN
    IF (
        MainTable[Randnumber] = MaxNumber,
        LOOKUPVALUE ( SourceTable[Sales], SourceTable[Id], MainTable[ID] )
    )

Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors