Getting the bottom values of a range in tag history

Tried searching high and low for this but having trouble finding anything remotely close. I am doing water monitoring in a hotel and we would like to get the bottom values of a tag for a given history range. The idea is that all things being “normal” in our hotel the average of the bottom 10% of our flow values for a given day should be 0. In SQL there is a function that does just this but I cannot find anything that will let me do it using the historian. I guess I could build a transaction set to fill a database for this purpose but that seems like overkill.

Any advice would be much appreciated!