Moving average of tag but only when another tag is on

Looking for a way to get the moving average (timeserieschart) of a base tag but only when another conditional tag is on. I’m thinking I have to make another tag (dataset) that references the base tag and the conditional tag. Loop through each row and delete if the conditional tag is 0. Hope to hear some better suggestions. Thanks!