Does entropy change when work in done on the system? Suppose, I have a cylinder filled with ideal gas molecules, and a piston is fitted at the top of the cylinder so that work can be done on and by the system. Now, if I do work on the system, isn't it the same as adding heat to the system?
Why then, does the formula only consider heat when calculating entropy?
$$dS=\frac{dQ}{T}$$
Can we not replace $dQ$ with $dW$, where $dW$ is the infinitesimal work done on the system?
 A: 
Does entropy change when work in done on the system?

Total entropy change equals entropy transferred plus entropy generated. Only heat transfers entropy. Reversible work itself does not transfer entropy. It is only the heat that may result from reversible work that transfers entropy. On the other hand, irreversible work does change (increase) entropy due to entropy generation.

Now, if I do work on the system, isn't it the same as adding heat to
the system?

It's the same only insofar as a differential change in internal energy $dU$ is concerned since they are related to the change by the first law
$$dU=\delta Q-\delta W$$
For example, if you did 10 J of compression work on the system but added no heat, or added 10 J of heat to the system but did no work, the change in internal energy would be the same, +10 J. After the change has occurred there is no way to know whether it was caused by heat or work. So in terms of the first law (conservation of energy) heat can be considered equivalent to work.
But work done on the system is not the same as adding heat to the system insofar as a change in entropy is concerned. If the 10 J of compression work was a reversible adiabatic process, then $\Delta S_{sys}=0$ because $Q=0$. If the 10 J of heat added was a reversible isochoric (constant volume) heat addition where $W=0$, then $\Delta S=mC_{v}\ln\frac{T_2}{T_1}$.

Why then, does the formula only consider heat when calculating
entropy?
$$dS=\frac{dQ}{T}$$

The equation
$$dS=\frac{\delta Q_{rev}}{T}$$
defines a differential change in entropy of a system for a reversible path, as in the reversible isochoric heat addition and reversible adiabatic compression examples above. Although the equation is for a reversible path, it is used to calculate the change in entropy for an irreversible path between the two equilibrium states since entropy is a state property independent of the path. However, for an irreversible path, you need to devise any convenient reversible path that satisfies the initial and final states per the first law.
For example, an irreversible adiabatic process generates entropy although there is no heat transfer. To determine the entropy increase you would devise any convenient reversible path connecting the initial and final states and apply the entropy equation to it. You would find that part of that path will require reversible heat transfer.
@Chet Miller has developed a helpful step by step approach to determine the change in entropy of a system. You can find it here:
https://www.physicsforums.com/insights/grandpa-chets-entropy-recipe/

Can we not replace $dQ$ with $dW$, where $dW$ is the infinitesimal work done on the system?

In the case of a reversible isothermal process involving an ideal gas, since $dU=0$, then $\delta Q=\delta W$, meaning the magnitude of energy transfer to/from the system in the form of reversible heat equals the magnitude of energy transfer from/to the system in the form of reversible work. But the fact the values are the same does not mean heat and work are equivalent with respect to entropy change as already stated above. It is reversible heat that transfers entropy, not reversible work.  For that reason I would be hesitant to substitute $\delta W$ for $\delta Q$ in the entropy equation as it may imply that heat and work are equivalent with respect to entropy change.
Hope this helps.
A: Work and heat are different concepts.
Work is a quantity which stems from a change in your system.
Heat is a quantity that stems from a change in energy coming from your environment i.e. outside your system.
Now consider the 1st law of thermodynamics
$$dE = \delta W + \delta Q$$
this is a phenomenological axiom which expresses the two different ways you can change the energy in your system when going from one equilibrium state to another. It is in this sense that heat and entropy are the same as you mention, they both change the energy but they are functionally different. The 1st law is also an exact differential, allowing us to express changes in energy.
Sticking to your example of a piston, we can begin to try and attain expressions for the inexact differentials in the expression above. Starting $\delta W$ this is obviously
$$W = - \int^{v_1}_{v_0}P dV$$
from observation. Giving us a path depentent way to evaluate work when moves from one equilibrium state to another in a state space (in this case some PV diagram).
For $\delta Q$ understanding how to attain an expression for this inexact differential is more challenging. We must define the notion of Carnot cycle (which predates the first law) and says that a maximally efficient transfer of heat occurs between two reservoirs when the following relationship is manifest
$$\frac{Q_1}{Q_2} = \frac{T_1}{T_2}$$
where $Q_i$ is the heat transferred from the $i$-th reservoir at temperatuvre $T_i$ through a Carnot cycle. From here we may postulate that any heat transfer may be decomposed into infinitessimal Carnot cycles giving
$$\frac{dQ_1}{T_1} = \frac{dQ_2}{T_2}.$$
For a reversible process we have
$$\oint \frac{dQ}{T_R} = 0$$
but if the process is irreversible we have
$$\oint \frac{dQ}{T_R} \leq 0$$
which is known as Clausius' Inequality. If one then quantifies this measure which takes us away from the optimal reversibility of a Carnot cycle and calls it entropy one has
$$ \Delta S_{A \rightarrow B} \geq \int^{B}_{A} \frac{dQ}{T}$$
or $dQ = TdS$ as you state for cyclic, reversible processes.
And so, $\delta W$ and $\delta Q$ cannot be interchanged because they refer to different quantities that describe different phenomena. And as such are expressed in and originate from different concepts. One from phenomenology, the other from the Carnot cycle.
