Sample calculates the mip level to sample based on screen space derivatives of the texture coordinates provided. Derivatives of texture coordinates can be computed as follows:
float2 derivX = ddx(myTexCoord.xy);
float2 derivY = ddy(myTexCoord.xy);
But this is hidden inside the Sample function implementation. You can achieve the same result by using SampleGrad function and providing the derivatives yourself:
float4 textureColor = myTexture.SampleGrad(mySampler, myTexCoord.xy, derivX, derivY);
If you use SampleLevel, that expects the mip level instead of the derivatives, but you could compute a mip level from the derivatives yourself and use SampleLevel:
float delta_max_sqr = max(dot(derivX, derivX), dot(derivY, derivY));
float mip = 0.5 * log2(delta_max_sqr) * myTexture_NumberOfMIPLevels;
float4 textureColor = myTexture.SampleLevel(mySampler, myTexCoord.xy, mip);
However the SampleLevel might not give the exact results of the Sample method because Sample can use a different method based on the sampler descriptor's MipFilter and MipLODBias settings.
Calculating derivatives using ddx and ddy needs information from neighbour pixels, so you can't use the functions inside dynamic branches or loops (which are maybe not running for neighboring pixels). In those cases the derivatives could be precomputed and you can use the SampleGrad or SampleLevel instructions inside the dynamic branches/loops.