#GROUPVAR problems

I am getting the following error in both a Screen or Custom Universe.

ERROR: When using #GROUPVAR you must set the variable @Group in a previous rule

ShowVar(@Group, Yield > 1.5)
SetVar(@r1, FRank(“OpMgn%TTM”,#GroupVar,#DESC))

#GroupVar only works in the screener and universes. See the small footnote on the reference.

Seems to work fine there.

Hello Marco, I am doing this in a Universe, so it should work. I am still getting the error.

I tested in a Screen and also Universe, and still getting the error

The error I am still getting is: ERROR: When using #GROUPVAR you must set the variable @Group in a previous rule

Can you save the screen and share the id ? (it’s in the URL)

https://www.portfolio123.com/app/screen/summary/277843?mt=1

Here it is

https://www.portfolio123.com/app/screen/summary/277843?mt=1

I was able to get this to work by moving the line with ShowVar(@Group, Yield > 1.5) up a ways. I have no idea why it didn’t work when it was on the eighteenth line but worked when it was on the seventh line. Must be a bug . . .

Yes the cause is the placement. It’s not a bug. When you use #GroupVar in an cross sectional function like FRank it operates on the universe, so all the stocks in the universe need the @Group variable set. But you are doing the setting of @Group after some filtering. It’s the stocks that were filtered that cause the problem.

So yes, the solution is to move the cross sectional function that uses #GroupVar above all filtering of stocks.

Hope that helps

PS, there are some inconsistencies in the documentation for the scope #GroupVar. The function FRank seems to say that it’s only in the screener and universe, but others like FCount seem to say that it’s not available only in the ranker. I’ll need to investigate some more.

Thanks Yval and Marck,

I am going to include anything that was before into formulas, and add the formula to the @Group, that way the @Group will be on top and includes my filtering. That should work

Thanks