You're using the two FIRSTNONBLANKs in the expression parameter (first argument) of your CALCULATE. At that point, context transition has occurred and all (previous) row contexts have been converted into filter contexts. The row context from the ADDCOLUMNS that you talk about correctly, is therefore no more. So you only have the row context from the FIRSTNONBLANK( ) and therefore the EARLIER( ) fails.
Hi, @AlB thanks for the explanation. I vaguely felt that CALCULATE() was the source of the problem and pretty glad to learn from you about context conversion. I read a few articles about that, but am more and more concerned about what contexts exactly are, in the Vertipaq engine, do you have any insight on this topic? I'm just curious, but I think understanding the database engine as well as the parsing of DAX is going to help a lot with writing them.
You're welcome. You always have interesting, well thought-out questions.
I'm not sure knowing the internals of the engine would help with that. I'm certainly no expert in it so don't take my word for it. Take into account, though, that in many cases the way operations are carried out at low level differs greatly from what you would expect. The engine is built with performance in mind and without the restriction to bear any resemblance to your code at the higher level. But like I said, do NOT take my word for it. If you see that it can actually help, please do let me know. I'd be interested in hearing about it.
My view is that it should be possible to understand contexts and context transition well without the need to delve into the engine.