cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

How to get Last N Rows of any Infotable

RK_0705
11-Garnet

How to get Last N Rows of any Infotable

Hi Team,

 

Just like to get N no of rows from top in any infotable ThingWorx provides default snippet as TopN method of InfotableFunctions , do we have any snippet to get Last N rows of any infotable?

 

Please share the snippet.

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions

@VladimirRosu @TonyZhang @VladimirN 

 

For now I have ignored the rows from starting which I don't want in my final infotable via for loop but it will be good to have some method which can provide Last N rows also of an infotable just like TopN method.

View solution in original post

5 REPLIES 5
VladimirN
24-Ruby II
(To:RK_0705)

 Hi,

 

There was a similar question before - "How to get certain number of rows from Infotable": https://community.ptc.com/t5/ThingWorx-Developers/How-to-get-certain-number-of-rows-from-Infotable/td-p/610708 

@VladimirN  The link shared is for First N Rows the method is TopN. But I need Last N Rows of an infotable.

TonyZhang
13-Aquamarine
(To:RK_0705)

@RK_0705,

 

Currently there's no LastN or BottomN snippet available but might be released in the future.

You can post your idea in below site.

https://community.ptc.com/t5/ThingWorx-Ideas/idb-p/thingworxideas

 

For now you can consider using built-in Sort function (snippet) to sort on a column in descending order so you get your infotable rearranged in reversed order.

Then use TopN to extract the rows you want.

 

And a (very simple) code-based alternative is the following:

// Simulation.DataShape is a custom DataShape I used for this test

let result = DataShapes["Simulation.DataShape"].CreateValues();

// test is the input infotable
let length = test.getRowCount();

// slice is a built in Javascript array method that will get us the last 2 rows in this situation; replace 2 with the desired number of last rows
test.rows.toArray().slice(length-2,length).forEach(row=>{result.addRow(row);});

@VladimirRosu @TonyZhang @VladimirN 

 

For now I have ignored the rows from starting which I don't want in my final infotable via for loop but it will be good to have some method which can provide Last N rows also of an infotable just like TopN method.

Top Tags