Yes, formatting complex DAX code like this will help enormously. Go to
paste in your code and click “Format” and it will automatically format it for you. Better yet, add this awesome little add-on from @samaguire and you can access DAX CleanUp and all the other Analyst Hub tools from your PBI External Tools menu:
With regard to your measures, EARLIER works fine in a calculated column, but can be very troublesome to get to work properly within a measure. SQLBI and eDNA both recommend retiring EARLIER in favor of an approach using variables and a standard CALCULATE/FILTER construct. @Greg does a great job walking through this issue with tons of examples in his DAX Patterns page on Obtaining Previous Row Value: