As a general rule on getting counters at script level, take a look, among many others at this and this threads and some others mentioned on them, where some sample and working code is posted to solve similar issues. Take a look at the following dummy script based on your description. Okay, it may seem too complex, but let's take a closer look.
DataOriginal is the source table, no calculations done so far, only data. At a first glance, we can see that there are two unique Part ID values A and B, they are not sorted in any particular order (as they will likely be retrieved from no matter the source). A has 4 different price changes, but one of them is zero and there are two equal price changes (and according to my script, I'm not counting them). B has 5 different price changes, but three of them are zero. So A should have 2 changes and B 3.
DataOriginal: LOAD * INLINE [ Part ID, Price Change A, 1 A, 2 B, 3 B, 2 A, 0 A, 1 B, 0 B, 0 B, 1 ]; DataChanges: LOAD "Part ID", "Price Change", If("Part ID" = Previous("Part ID"), If("Price Change" <> 0, If("Price Change" <> Previous("Price Change"), RangeSum(Peek('HasChanged'), 1), Peek('HasChanged')) , 0) , 0) AS HasChanged RESIDENT DataOriginal ORDER BY "Part ID", "Price Change" ASC; DROP TABLE DataOriginal; NoOfChanges: LOAD "Part ID", Max(HasChanged) AS TotalNoOfChanges RESIDENT DataChanges GROUP BY "Part ID";
The second table does most of the trick, first, it checks that the Part ID is the same as in the previous record. Note that as the table is order by Part ID, all A values will go together, then the B, and that likewise the price changes are ordered ascending, so I can easily compare to the previous value. If the price change is not zero, then add 1 to the HasChanged counter field. But if the Part ID is not the same as in the previous record, then set the counter to zero because another Part ID starts its count.
Another tricky part is the use of the Peek() function. Fields only exist once the table has been completely loaded. "HasChanged" will not exist until the last row from the table DataOriginal is loaded. Well, kind of. Fields do only exist once the row has been loaded, but you can retrieve a value from that not-still-existing-field using Peek() (read "give me the lastest value of the field HasChanged"). Peek() has some other uses, as well.
But say I only want to know how many changes each Part ID has had, there the second table does a simple aggregation using the Max() function to return, group by Part ID the highest value of each counter.
Hope that makes sense.
Updated: Attached application with the script and simple table boxes.
qcomPriceChanges.qvw 149.8 K