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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Jiro
Frequent Visitor

How to let query pick the latest data from multiple columns?

Hi everyone, I am kind of new here so would really appreciate your help.


How do we create a new column and pick the latest status out of multiple of existing columns?

 

The sequence of the activies are:

1. Container Gate In Loading

2. Contained Loaded on Vessel

3. Vessel Departed

4. Container Arrived

 

However, when creating a new columns I want it to check from the last one (arrived) then back to the beginning (gate in loading). 

Based in below screenshots, it should start checking from the far right and since there is no value it will keep checking to gate in and then return as "gate in loading" in a new column.

IMG_1517.png

 

Thank you in advance.

 

 

 

 

2 ACCEPTED SOLUTIONS
v-cgao-msft
Community Support
Community Support

Hi @Jiro ,

I'm assuming this is a PowerQuery question, Please add a custom column:

if not List.IsEmpty(List.RemoveNulls({[Container Arrived]})) then "Arrived"
else if not List.IsEmpty(List.RemoveNulls({[Vessel Departed]})) then "Departed"
else if not List.IsEmpty(List.RemoveNulls({[Contained Loaded on Vessel]})) then "Loaded on Vessel"
else if not List.IsEmpty(List.RemoveNulls({[Container Gate In Loading]})) then "Gate In Loading" 
else null

vcgaomsft_1-1695003006028.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

m_dekorte
Super User
Super User

@Jiro 

Seems I misread your requirement. you could do something like this:

let
    Source = Table.FromRows(
        {
            {#date(2023,9,15), null, null, null},
            {#date(2023,9,15), #date(2023,9,17), null, null},
            {null, #date(2023,9,15), null, null},
            {#date(2023,9,15), null, #date(2023,9,18), null},
            {null, null, null, #date(2023,9,19)}
        },
        type table[Loading=date, Vessel=date, Departed=date, Arrived=date]
    ),
    AddCustom = Table.AddColumn(Source, "Custom", each 
        Record.FieldNames(_){
            List.PositionOf(
                Record.FieldValues(_), 
                [Arrived] ?? [Departed] ?? [Vessel] ?? [Loading], 
                Occurrence.Last 
            )
        }
    )
in
    AddCustom

 

to obtain this result

m_dekorte_0-1695046900602.png

 

I hope this is helplful

Ps. Please mark this answer as solution when it helped you to resolve your question, thanks!

View solution in original post

3 REPLIES 3
m_dekorte
Super User
Super User

@Jiro 

Seems I misread your requirement. you could do something like this:

let
    Source = Table.FromRows(
        {
            {#date(2023,9,15), null, null, null},
            {#date(2023,9,15), #date(2023,9,17), null, null},
            {null, #date(2023,9,15), null, null},
            {#date(2023,9,15), null, #date(2023,9,18), null},
            {null, null, null, #date(2023,9,19)}
        },
        type table[Loading=date, Vessel=date, Departed=date, Arrived=date]
    ),
    AddCustom = Table.AddColumn(Source, "Custom", each 
        Record.FieldNames(_){
            List.PositionOf(
                Record.FieldValues(_), 
                [Arrived] ?? [Departed] ?? [Vessel] ?? [Loading], 
                Occurrence.Last 
            )
        }
    )
in
    AddCustom

 

to obtain this result

m_dekorte_0-1695046900602.png

 

I hope this is helplful

Ps. Please mark this answer as solution when it helped you to resolve your question, thanks!

v-cgao-msft
Community Support
Community Support

Hi @Jiro ,

I'm assuming this is a PowerQuery question, Please add a custom column:

if not List.IsEmpty(List.RemoveNulls({[Container Arrived]})) then "Arrived"
else if not List.IsEmpty(List.RemoveNulls({[Vessel Departed]})) then "Departed"
else if not List.IsEmpty(List.RemoveNulls({[Contained Loaded on Vessel]})) then "Loaded on Vessel"
else if not List.IsEmpty(List.RemoveNulls({[Container Gate In Loading]})) then "Gate In Loading" 
else null

vcgaomsft_1-1695003006028.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

m_dekorte
Super User
Super User

There are several way to achieve this, the most simple would be applying coalesce (dubble question mark), this will return the first non-null value - if all values are null a null is returned.

 

To illustrate, coalesce will look like this, you insert the coalesce operator between each field selection: 

[Col4] ?? [Col3] ?? [Col2] ?? [Col1]

 

 

Ps. Please mark this answer as solution when it helped you to resolve your question, thanks!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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