Umar bin Al-Khattab (May ALLAH be pleased with him) said: “I heard Allah’s Messenger (May peace and blessings be upon him) saying, “The reward of deeds depends upon the intentions and every person will get the reward according to what he has intended. So whoever emigrates for worldly benefits or for a woman to marry, his emigration will be for what he emigrated for.””
This is how our deeds are measured, by our intentions. Someone may have done something good but if his intentions are not pure or he did not intend to do good but to show off, then it will not count. May ALLAH give us ability to make right intentions for all that we do.