Forum Discussion
Replace Value Based on latest date
- 5 years ago
=Table.Combine(Table.Group(Source,"Name",{"n",each let NewLocation=Table.First(Table.Sort(_,{"Date",1}))[Location] in Table.ReplaceValue(_,null,NewLocation,(x,y,z)=>z,{"Location"})})[n])
Daniel,
Thanks for your reply. You code worked, unfortunately I didn't clearly state that I would have multiple "Names".
Is it possible for you to modify so we are getting the most recent location by date for each name?
Somebody's locations would be Location2
Somebody2's locations would be Location6
Somebody3's locations would be Location13
Thank you!
- wdx223_Daniel5 years agoCommunity Champion
=Table.Combine(Table.Group(Source,"Name",{"n",each let NewLocation=Table.First(Table.Sort(_,{"Date",1}))[Location] in Table.ReplaceValue(_,null,NewLocation,(x,y,z)=>z,{"Location"})})[n])
- eyespike15 years agoFrequent Visitor
That worked! Thank you so much!
- K_L_G3 years agoRegular Visitor
Hello, thank you for the very helpful formula! I have the exact same issue as eyespike1, and this forum has been a blessing.
One stumbling block I have encountered: Are you able to advise on excluding nulls as the most recent value? Example:
In this scenario, I want:
Somebody's locations would be Location3
Somebody2's locations would be Location6
Somebody3's locations would be Location12
Edit: The only option I have found is adding a helper column that tags rows w/ number in "Location" as "1" and nulls as "2". Then modifying the Table.Sort step to sort by both the helper column and Date column. Is the the only / best way?
thank you!