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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Calculating how many times a property value repeats in QueryPropertyHistory Service

Aditya1702
15-Moonstone

Calculating how many times a property value repeats in QueryPropertyHistory Service

Hi,

I have logged property into a value stream and using QueryPropertyHistory service I am able to have a view at the recorded data of the logged properties. What next I wan to achieve is how can we calculate the number of times a value of a property repeats in the data recorded, upto a particular date.

 

eg, I have property called stepValueStatus which has a string value pass/fail. So I want to calculate how many times pass occurs and how many times fail occurs for this stepValueStatus property.

 

Thanks in Advance.

 

Regards,

Aditya Gupta

ACCEPTED SOLUTION

Accepted Solutions
Velkumar
19-Tanzanite
(To:Aditya1702)

Hi @Aditya1702 

 

Set your service Output as InfoTable and set DataShape to it.

 

In Mashup, Call this service and map output to Grid Widget.

Velkumar_0-1710842053041.png

 

 

/VR

View solution in original post

8 REPLIES 8
Velkumar
19-Tanzanite
(To:Aditya1702)

Hi @Aditya1702 

 

You can use the Aggregate Function to get a count of values

 

let params = {
    t: me.dummyInfoTable/* INFOTABLE */,
    columns: "name" /* STRING */,
    aggregates: "COUNT" /* STRING */,
    groupByColumns: "name" /* STRING */
};

// result: INFOTABLE
let result = Resources["InfoTableFunctions"].Aggregate(params);

Input:

Velkumar_1-1710833891309.png

 

Output :

Velkumar_0-1710833856610.png

 

/VR

 

 

Aditya1702
15-Moonstone
(To:Velkumar)

Hi @Velkumar ,

What to add in place of dummyInfotable since I don't have any infotable I get infotable as an output of QueryPropertyHistory Service.

Can you please elaborate a bit more since, I am new to ThingWorx.

 

Thanks in Advance.

 

Regards,

Aditya Gupta

 

Velkumar
19-Tanzanite
(To:Aditya1702)

Hi @Aditya1702 

 

Replace me.dummyInfoTable with an output of QueryPropertyHistory service

 

var data = me.QueryPropertyHistory({
    maxItems: undefined /* NUMBER {"defaultValue":500} */,
    startDate: undefined /* DATETIME */,
    endDate: undefined /* DATETIME */,
    oldestFirst: undefined /* BOOLEAN */,
    fillOption: undefined /* STRING {"defaultValue":"Previous"} */,
    query: undefined /* QUERY */
});


let params = {
    t: data /* INFOTABLE */,
    columns: "FIELDNAME_TO_COUNT" /* STRING */,
    aggregates: "COUNT" /* STRING */,
    groupByColumns: "FIELDNAME_TO_COUNT" /* STRING */
};

// result: INFOTABLE
let result = Resources["InfoTableFunctions"].Aggregate(params);

 

/VR

Aditya1702
15-Moonstone
(To:Velkumar)

Hi @Velkumar ,

 

Thank you it did worked!!!

One more thing what if I want to display these counts (T1 as 3, T2 as 2 & T3 as 1) in mashup how can I go about this?

Velkumar
19-Tanzanite
(To:Aditya1702)

Hi @Aditya1702 

 

Set your service Output as InfoTable and set DataShape to it.

 

In Mashup, Call this service and map output to Grid Widget.

Velkumar_0-1710842053041.png

 

 

/VR

Aditya1702
15-Moonstone
(To:Velkumar)

Hi @Velkumar ,

 

Thanks a lot for your quick help.

 

Thanks & Best Regards,

Aditya Gupta

Aditya1702
15-Moonstone
(To:Velkumar)

Hi @Velkumar ,

Good Evening,

 

I am facing problem in logging properties there are some values which are repeating after I carry out the experience third time.

PFA attached image in which arrows are shown on the readings which are repeating when I consume the AR experience on my Ipad on view app the third time.

 

Thanks in Advance.

 

Hello,

 

The repetition of the values is random.

Can anyone help me out with this?

 

Thanks in Advance.

Announcements


Top Tags