In the general AntiFactor problem, a graph G is given with a set Xv ⊆ N of forbidden degrees for every vertex v and the task is to find a set S of edges such that the degree of v in S is not in the set Xv. Standard techniques (dynamic programming + fast convolution) can be used to show that if M is the largest forbidden degree, then the problem can be solved in time (M + 2) tw • n O(1) if a tree decomposition of width tw is given. However, significantly faster algorithms are possible if the sets Xv are sparse: our main algorithmic result shows that if every vertex has at most x forbidden degrees (we call this special case AntiFactorx), then the problem can be solved in time (x + 1) O(tw) • n O(1) . That is, the AntiFactorx is fixed-parameter tractable parameterized by treewidth tw and the maximum number x of excluded degrees.Our algorithm uses the technique of representative sets, which can be generalized to the optimization version, but (as expected) not to the counting version of the problem. In fact, we show that #AntiFactor1 is already #W[1]-hard parameterized by the width of the given decomposition. Moreover, we show that, unlike for the decision version, the standard dynamic programming algorithm is essentially optimal for the counting version. Formally, for a fixed nonempty set X, we denote by X-AntiFactor the special case where every vertex v has the same set Xv = X of forbidden degrees. We show the following lower bound for every fixed set X: if there is an > 0 such that #X-AntiFactor can be solved in time (max X + 2 − ) tw • n O(1) on a tree decomposition of width tw, then the Counting Strong Exponential-Time Hypothesis (#SETH) fails.