Metric sampling

We have table with counter value which just gets incremented. I would like to find the difference between last value and current value.
Do we have a function to check difference between last and current values based on the timestamp function?

The question isn’t clear, could you clarify? If you share the DDL and queries/pseudocode it might make it more clear.