Your assumption is not correct.
-
Function WriteIf works perfectly fine and Writeif output is correct according to what documentation is telling you. Reading (entire documentation from top to bottom) is important:
Please note that WriteIf returns just single string representing current SelectedValue of the EXPRESSION
Selected Value in analysis is at last bar of set range .
-
For what you want to do you have to use different function and the solution to your request is here.