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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
briceem
Frequent Visitor

Create column from last value of another column which is a list of record

Hi

 

I have a table (obtained from a custom api API) containing different columns. To simplify let's say we have the following:

hostname  ip history
host11.1.1.1List
host22.2.2.2List
host33.3.3.3List

 

Each List in the column history is list of Record. The records have three columns "date", "version" and "type". All types are currently string (and I'm not opposed to cast those but for performance reason, and because I'm new to Power BI, I'd prefer to do it later in the process). 

 

So for example the column history for the host1 object is like this:

date  typeversion
2021-03-11T16:36:28.628Ztype11
2022-04-01T04:53:10.805Ztyperandom2
2023-04-01T02:53:10.805Ztype83

 

 

My objective is to get a new column in my first table containing the last value of the column "date" based on the last "version" (for this particular host of course) I can find in this List.

NB: If that can help, this list is already ordered, but I would prefer to use something like List.Max instead of List.Last in case the API changes.

 

So the result should produce

hostnameiphistorylast_date
host11.1.1.1List2023-04-01T02:53:10.805Z
host22.2.2.2List2022-08-01T05:51:12.704Z
host33.3.3.3List2023-07-01T10:04:10.105Z

 

 

 

I already successfully found a way to extract the max version and get the date for one line, but I don't know how to use this in the function that I found to add column :

Table.ExpandTableColumn

 

Here is my current code for this array

 

 

 

 

 

 

 

 

let
   Source = GetMyLines(),
   headers =
       let
           allHeaders = List.Combine(List.Transform(Source, Record.FieldNames)),
           uniqueHeaders = List.Distinct(allHeaders)
       in
           uniqueHeaders,
   myTable = Table.FromRecords(Source, headers, MissingField.UseNull),
   //test on one line
   history = myTable{0}[history],
   // get date for this line with the highest version
   maxvalue = Table.Max(Table.FromList(history,Record.FieldValues,{"date","type","version"}),"version")[date]
in
   maxvalue

 

 

 

 

 

 

 

 

 

 

Thanks in advance

1 ACCEPTED SOLUTION
rubayatyasmin
Super User
Super User

Hi, @briceem 

 

Your objective is to find the most recent date for each version for each hostname. You need to iterate over each row of your initial table and apply your logic to each history.

 

try updating from this line

 

myTable = Table.FromRecords(Source, headers, MissingField.UseNull),

-->// Add column
WithLastDate = Table.AddColumn(myTable, "last_date", each let history = [history],
historyTable = Table.FromList(history,Record.FieldValues,{"date","type","version"}),
maxvalue = Table.Max(historyTable,"version")[date]
in maxvalue)
in
WithLastDate

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


View solution in original post

2 REPLIES 2
rubayatyasmin
Super User
Super User

Hi, @briceem 

 

Your objective is to find the most recent date for each version for each hostname. You need to iterate over each row of your initial table and apply your logic to each history.

 

try updating from this line

 

myTable = Table.FromRecords(Source, headers, MissingField.UseNull),

-->// Add column
WithLastDate = Table.AddColumn(myTable, "last_date", each let history = [history],
historyTable = Table.FromList(history,Record.FieldValues,{"date","type","version"}),
maxvalue = Table.Max(historyTable,"version")[date]
in maxvalue)
in
WithLastDate

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Hi @rubayatyasmin,

You're amazing !
I will have to dig into some Table.AddColumn definition because I don't fully understand your syntax but your solution is working perfectly and I'm pretty sure I will be able to adapt it for other use cases.

 

Thanks again

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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