You can check the y-coordinate of a mark on a page and perform a comparison to decide whether you should print above or below. zref's savepos module can help with that:

\documentclass{article}
\usepackage{zref-savepos}
\newcounter{whereq}
\newcommand{\location}[1]{\zsaveposy{#1}}
\newcommand{\where}[1]{%
\stepcounter{whereq}% New "where" request
\location{whereq-\thewhereq}% Mark location
% Test location based on y-coordinate
\ifdim\zposy{whereq-\thewhereq}sp<\zposy{#1}sp
above%
\else
below%
\fi}
\begin{document}
As mentioned \where{test}, $2+2=4$.
We state that $2+2=4$.\location{test}
As mentioned \where{test}, $2+2=4$.
\end{document}
Of course, the above doesn't really care what page you perform the \location and \where macros on. However, it could be extended to condition on the page number as well.
abovewhen the page and the label are on the same page. But what if I always want to useaboveandbelow. This only seems to specifyaboveassuming that the label is above the reference. I can't make this assumption. – Marnix Oct 21 '11 at 23:22variorefdoes allow this kind of automatic switching between 'above' and 'below'. – Simifilm May 15 '13 at 08:51I was just referenced to this question/threads by a comment there...
– kmindi Jun 02 '22 at 12:40