Let A 1 , . . . , Ar be linear partial differential operators in N variables, with constant coefficients in a field K of characteristic 0. With A := (A 1 , . . . , Ar), a polynomial u is A-harmonic if Au = 0, that is, A 1 u = · · · = Aru = 0.Denote by m i the order of the first nonzero homogeneous part of A i (initial part). The main result of this paper is that if r ≤ N , the dimension over K of the space of A-harmonic polynomials of degree at most d is given by an explicit formula depending only upon r, N , d, and m 1 , . . . , mr (but not K) provided that the initial parts of A 1 , . . . , Ar satisfy a simple generic condition. If r > N and A 1 , . . . , Ar are homogeneous, the existence of a generic formula is closely related to a conjecture of Fröberg on Hilbert functions.The main result holds even if A 1 , . . . , Ar have infinite order, which is unambiguous since they act only on polynomials. This is used to prove, as a corollary, the same formula when A 1 , . . . , Ar are replaced with finite difference operators. Another application, when K = C and A 1 , . . . , Ar have finite order, yields dimension formulas for spaces of A-harmonic polynomial-exponentials.2010 Mathematics Subject Classification: 35G05, 15A06, 65L12.