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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Deep lookup over column pair

Let's simplify dataset on which I'm working to 3 columns - step_idprevious_step, meta. What I want to achieve is to fill in meta of any row lacking this value with meta of any entry in a certain step chain (i.e. any meta from group of steps that has the same "earliest" step). I assume that the metadata is always the same for all entries created by a certain step (so selecting which step to base new meta on is not an issue).

I was thinking on adding a column for the "earliest" step in certain chain, so that I could use something like FIRSTNONBLANK() over the filtered table, but had no luck doing it with DAX and I lack PowerQuery fluency to develop it myself.

Is this doable in PowerQuery or, preferably, DAX?

 

This is a sample of what I would want to achieve:

 

step_idprevious_stepmetaearliestmeta_filled
1blankblank1US
21blank1US
31US1US
4blankblank4blank
5blankblank5UK
65blank5UK
76UK5UK
87blank5UK

 

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Is the screenshot your expected output?

Capture.PNG

 

Just create a calculated column for getting the first step:

 

 

Column = IF('Table'[previous_step] = BLANK(),'Table'[step_id],BLANK())

 

 

Capture1.PNG

 

Then use dax to fill down:

 

 

first_step =
VAR LastNonBlankStep =
    CALCULATE (
        LASTNONBLANK ( 'Table'[step_id], 1 ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[step_id] <= EARLIER ( 'Table'[step_id] )
                && NOT ( ISBLANK ( 'Table'[Column] ) )
        )
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[Column] ),
        FILTER ( ALL ( 'Table' ), 'Table'[step_id] = LastNonBlankStep )
    )

 

 

Capture2.PNG

 

For more details, please refer to the pbix file:https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/ERXKTCCXNOVCrS1Fwsw6W4IB91H3Ib8IaZDbBvb8hn6uYg?e=hKvZOS

 

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

 

Best Regards,

Dedmon Dai

 

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@Anonymous ,The information you have provided is not making the problem clear to me. Can you please explain with an example.

Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

My dataset is a list of processing steps that are, at the system from which the data originates, grouped into processings, however tha only remnant of this is th column previous_step - it is blank if a step is the first one of its processing and it points to a previous one if not. 

 

I want to be able to lookup the earliest step in a processing for each single step, so that I'm able to group them back into processings, so that values from other columns could be aggregated/looked up

Hi @Anonymous ,

 

I still can't get the expected output you want from your description. Would you please show us more details and expected output based on your sample data?

 

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

 

Best Regards,

Dedmon Dai

Anonymous
Not applicable

Let's generalize it further.

 

Input:

step_idprevious_step
1 
21
32
4 
54
64
76
83

 

Output:

step_idprevious_stepfirst_step
1 1
211
321
4 4
544
644
764
831

 

 

Hi @Anonymous ,

 

Is the screenshot your expected output?

Capture.PNG

 

Just create a calculated column for getting the first step:

 

 

Column = IF('Table'[previous_step] = BLANK(),'Table'[step_id],BLANK())

 

 

Capture1.PNG

 

Then use dax to fill down:

 

 

first_step =
VAR LastNonBlankStep =
    CALCULATE (
        LASTNONBLANK ( 'Table'[step_id], 1 ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[step_id] <= EARLIER ( 'Table'[step_id] )
                && NOT ( ISBLANK ( 'Table'[Column] ) )
        )
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[Column] ),
        FILTER ( ALL ( 'Table' ), 'Table'[step_id] = LastNonBlankStep )
    )

 

 

Capture2.PNG

 

For more details, please refer to the pbix file:https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/ERXKTCCXNOVCrS1Fwsw6W4IB91H3Ib8IaZDbBvb8hn6uYg?e=hKvZOS

 

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

 

Best Regards,

Dedmon Dai

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.