Hi.
I don't have your data, so I composed an example with my data. So yes, you don't need my first line.
You said you want to return 1 if the row belongs to the upper 30%. My rows 8, 9, and 10 are greater than the 70% quantile, which is the same as being in the upper 30%, and so return 1.
If this is not exactly what you want, does this provide enough of an example so that you can change it to what you want?