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

How to Retrieve infotable data row selected from aggregate function

AliceHdzR
Visitor

How to Retrieve infotable data row selected from aggregate function

Hello, I am looking to get the minimum column value from an infotable using the aggregates function. The issue is that the aggregates result, it only retrieve the min value.

I want to know how retrieve the entire row of the infotable that the aggregates selected as a result. ¿Is that possible?

This is my code:

var params = {
t: infoTable /* INFOTABLE */,
columns: "RD_MP_PRED" /* STRING */,
aggregates: "MIN" /* STRING */,
groupByColumns: undefined /* STRING */
};

result = Resources["InfoTableFunctions"].Aggregate(params );

The result variable is a number.

3 REPLIES 3

Re: How to Retrieve infotable data row selected from aggregate function

Hi @AliceHdzR.

 

One option would be to pass the result back in to retrieve the rows matching that value via find and filter functions.  For your scenario, the EQFilter sounds like the best choice.  The EQFilter is a service available in the Infotable Functions resource.

 

Regards.

 

--Sharon 

 

 

Re: How to Retrieve infotable data row selected from aggregate function

Hi @slangley ,

thank you for your response, I don´t really wanted to do that but I guess I will have to use that strategy as a solution because I cannot find another way for retrieve more information of the selected aggregates function result, it only gives me the minimum value.


Here is my code, I hope this could help someone else:

//First I get the minimum value groupByColumns ORDEN (I used this name as an ID) because dataVerdes has several duplicated rows, so I have to apply the group by.

var MINVerde = Resources["InfoTableFunctions"].Aggregate({
t: dataVerdes /* INFOTABLE */,
columns: "RD_MP_PRED" /* STRING */,
aggregates: "MIN" /* STRING */,
groupByColumns: "ORDEN" /* STRING */
});

//The result of MINVerde is a 2 column and 3 different rows infotable with their minimum value and the ORDEN value

//Then I get the minimum of MINVerde but with groupByColumns as undefined, so I can get only 1 result

var MINVerde2 = Resources["InfoTableFunctions"].Aggregate({
t: MINVerde /* INFOTABLE */,
columns: "MIN_RD_MP_PRED" /* STRING */,
aggregates: "MIN" /* STRING */,
groupByColumns: undefined /* STRING */
});

 

//This is the solution suggested, I generate the EqFilter, so I can compare the result of MINVerde2 vs MINVerde result (that has 2 columns and 3 rows)
var vMinRpMpPred = MINVerde2.rows[0].MIN_MIN_RD_MP_PRED;
var queryMinVal = {
"filters": {
"fieldName": "MIN_RD_MP_PRED",
"type": "EQ",
"value": vMinRpMpPred
}
};
var dataMinVerde = Resources['InfoTableFunctions'].Query(
{
query : queryMinVal,
t : MINVerde
});

result = dataMinVerde;

//And finally the result is an infotable with the information of the MINVerde that contains also the column ORDEN, not only the minimum value.

Re: How to Retrieve infotable data row selected from aggregate function

Hi @AliceHdzR.

 

Someone else in the developer community may have a better idea, but at least you have a workaround for now.

 

Regards.

 

--Sharon

Announcements

Check out the upcoming Expert Session: Understanding ThingWorx Navigate Licensing in Community "Customer Events" section.