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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
jpolanco
New Member

Retrieving last non null value grouped by key N_order

Hi everybody,

 

I'm trying to plug the holes on the dataset that I'm currently working on.

My N_order is the key for grouping. As you can see in below example, I've null values for the column ship_meth, when the status is 'fulfilled'.

I'd love to create a new desired_column that can retrieve the value from any of the other statuses for that N_order (for example, 'new_order') and paste it on the row with the 'fulfilled' status.

 

I'm not able to provide a solid example of what I've been trying, as is not working anywhere near what I'd like. Just going to point out that it doesnt work with filldown/up function as i've different statuses on the orders, and different ship_meth.

 
N_orderShip_methstatusdesired_column
50010000116187ENKMpickedENKM
50010000116187ENKMacceptedENKM
50010000116187nullfulfilledENKM
50010000116325nullfulfilledENRC
50010000116325ENRCacceptedENRC
50010000116325ENRCrejectedENRC

 

Appreciate your time and effort.

 

Suk

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjUwMDQAAkNDM0MLcyUdJVc/b18gVZCZnJ2aAuPH6uBWmZicnFpQQkAtEKWV5qRl5uTgVGhsZIpNYZAzdoVgGTTbCagtSs1KTUZWGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [N_order = _t, Ship_meth = _t, status = _t, desired_column = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each if [Ship_meth] = null or [Ship_meth]="" then Table.SelectRows(Source,(k)=>[N_order]=k[N_order] and k[Ship_meth]>"")[Ship_meth]{0} else [Ship_meth])
in
    #"Added Custom"
How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

=if(Data[status]="fulfilled",CALCULATE(MIN(Data[Ship_meth]),FILTER(Data,Data[N_order]=EARLIER(Data[N_order]))),Data[Ship_meth])

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjUwMDQAAkNDM0MLcyUdJVc/b18gVZCZnJ2aAuPH6uBWmZicnFpQQkAtEKWV5qRl5uTgVGhsZIpNYZAzdoVgGTTbCagtSs1KTUZWGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [N_order = _t, Ship_meth = _t, status = _t, desired_column = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each if [Ship_meth] = null or [Ship_meth]="" then Table.SelectRows(Source,(k)=>[N_order]=k[N_order] and k[Ship_meth]>"")[Ship_meth]{0} else [Ship_meth])
in
    #"Added Custom"
How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.