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
ashleylinkewich
Advocate II
Advocate II

Lookup Value from related Row - Related with a key

Hi all,

 

I want to look up a related value from a previous row in a table. It looks like this: 

 

ContractJobReturnedLoadKey
AB078912345
AB1****12345
AB045667891
AB0****67891
AB1****67891

Basically I want to fill in the load column where the returned column is equal to 1, using the key column, i.e the first **** would be 789 and the second/third 456.

 

Is there any way to do this? I couldn't get my syntax right on either earlier or lookup functions. 

 

Thank you! 

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

hi @ashleylinkewich 

Basically I want to fill in the load column where the returned column is equal to 1, using the key column, i.e the first **** would be 789 and the second/third 456.

the returned column of the second **** is 0, it doesn't meet the conditional.

Then you could try this way:

First, you need  to add an index column in the table.

Second, create a column as below:

Column = 
IF (
    'Table'[Load] <> "****",
    'Table'[Load],
    IF (
        'Table'[Returned] = 1,
        CALCULATE (
            MAX ( 'Table'[Load] ),
            FILTER (
                'Table',
                'Table'[Key] = EARLIER ( 'Table'[Key] )
                    && 'Table'[Index] < EARLIER ( 'Table'[Index] )
            )
        ),
        "****"
    )
)

or

Column 2 = 
IF (
    'Table'[Load] <> "****",
    'Table'[Load],
    IF (
        'Table'[Returned] = 1,
        CALCULATE (
            MAX ( 'Table'[Load] ),
            FILTER (
                'Table',
                'Table'[Key] = EARLIER ( 'Table'[Key] )
                    && 'Table'[Index] < EARLIER ( 'Table'[Index] )
            )
        )
))

Result:

5.JPG

 

and here is sample pbix file, please try it.

 

Regards,

Lin

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

View solution in original post

2 REPLIES 2
v-lili6-msft
Community Support
Community Support

hi @ashleylinkewich 

Basically I want to fill in the load column where the returned column is equal to 1, using the key column, i.e the first **** would be 789 and the second/third 456.

the returned column of the second **** is 0, it doesn't meet the conditional.

Then you could try this way:

First, you need  to add an index column in the table.

Second, create a column as below:

Column = 
IF (
    'Table'[Load] <> "****",
    'Table'[Load],
    IF (
        'Table'[Returned] = 1,
        CALCULATE (
            MAX ( 'Table'[Load] ),
            FILTER (
                'Table',
                'Table'[Key] = EARLIER ( 'Table'[Key] )
                    && 'Table'[Index] < EARLIER ( 'Table'[Index] )
            )
        ),
        "****"
    )
)

or

Column 2 = 
IF (
    'Table'[Load] <> "****",
    'Table'[Load],
    IF (
        'Table'[Returned] = 1,
        CALCULATE (
            MAX ( 'Table'[Load] ),
            FILTER (
                'Table',
                'Table'[Key] = EARLIER ( 'Table'[Key] )
                    && 'Table'[Index] < EARLIER ( 'Table'[Index] )
            )
        )
))

Result:

5.JPG

 

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
HotChilli
Super User
Super User

Could you clarify the logic please?

 

"fill in the load column where the returned column is equal to 1"  this would leave 2 records to be filled,

but "i.e the first **** would be 789 and the second/third 456." that would be 3 records.

 

If all records are to be filled , this would be a Fill Down in Power Query (make sure the table is sorted correctly first)

 

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.