For last 30 days(which i will select in time filter) I would like to get the count of field X only if it is older than 7days from current time.
Doesn't this work for you?
index=<yourindex> earliest=-30d latest=-7d | stats count(X)