For any complex separable Hilbert space $H$, we know that if $A:H\dashrightarrow H$ is an unbounded self-adjoint operator, then there exists some $\sigma$-finite measure space $(X,\mu)$, some unitary map $U:H\to L^2(X,\mu)$, and some $g:X\to\mathbb{R}$ measurable such that $AU=U M_g$, where $M_g:f\mapsto fg$ for $f\in L^2$.
My question is, when can we take $(X,\mu)$ to be some measure space with the counting measure? In the bounded case, it suffices to assume that $A$ is a compact operator, but that's not a clearly-defined notion in the unbounded case.