I can tell that you previously has the SUM() outside the "IF" logic, and you were on the right track there.
The problem you had with aggregates and non-aggregates was in the date difference calc. Don't need the ATTR in there.
Also I displayed the DATEDIFF result for the previous "to-date" value you are getting in the [Sales Previous Period] calc. You really want to subtract ([Date Difference] + 1). otherwise you'll be ending the previous range on the start of the current range.
Thanks for answering Joe. Removing ATTR from my DATEDIFF calculation worked.
The reason I was using ATTR(DATEDIFF) was that it would show the actual date difference eg. 61, where DATEDIFF without ATTR produces a result of 279,000 for dates 5/1/2017 to 6/30/2017.