Help with understanding why "のか" is used in this sentence


I read this sentence:

"私はなぜ彼がこれをしているのか、分からない"

The sentence is supposed to mean "I don't understand why he is doing this,"
and I think it is grammatically correct since I found it in a japanese site (
but if it is not, please help with correcting it ? ). My question is, why is
のか used in this sentence? When is のか used? I know how to use のが and のは、but のか
looks new to me. Can it be replaced by のが？ ( 私は彼がこれをしているのが、分からない ).

