I had this exact issue, where when I flipped the sensor to different orientations I would measure gravity as being anywhere between 7 m/s^2 to 10.5 m/s^2. I came to the same solution that st2000 is describing. I'm a little late to this conversation but I figured I can still share my solution to help anyone else who's experiencing the same issue.
First, I flipped the sensor on all 6 sides to record the approximate maximum and minimum acceleration I got for each axis due to gravity (each axis should read somewhere around 16,000 to 17,000 assuming the sensitivity is set to 2G).
My readings at this point were:
Minimum | Maximum
X | -15,700 | 17,000
Y | -16,650 | 16,250
Z | -16,600 | 16,800
Then I derived a linear correction formula that would take the raw readings from the accelerometer and output the acceleration in m/s^2. I first calculated the "center offset" of each axis by just averaging the minimum and maximum readings for each axis.
axis_min + axis_max
Center = ---------------------
2
Then I scaled the output according to its range so that when the axis reading was at the maximum, the output would be 9.8, and when the raw reading was around the minimum it would output -9.8.
G = 9.80665 (Acceleration due to gravity)
Range = axis_max - axis_min
G
----------- 2 * G 2 * G
Scale = Range = ------- = ---------------------
------- Range axis_max - axis_min
2
Now putting it all together we get the following linear equation to calculate the acceleration on each axis:
2 * G z_min + z_max
A(x) = Scale * (x - Center) = --------------------- * (x - ---------------)
axis_max - axis_min 2
The function in actual code looks like this:
float axis_correction(float raw_reading, float axis_min, float axis_max, float grav_accel) {
return (float)(2.f * grav_accel * (raw_reading - (axis_min + axis_max) / 2.f)) / (axis_max - axis_min);
}
Now, with this I get a consistent 9.75 to 9.88 m/s^2, I'm guessing with more tuning I can get this variation down further but this is already much better than the readings I was getting using any of the libraries out there. For reference, here's the plot for the accelerometer readings I got.

The plot shows us the processed readings. The red line is the total magnitude of the acceleration the sensor is experiencing. The purple line plots the nominal acceleration due to gravity. The other three lines are the individual accelerations on each axis. As we can see, the magnitude of acceleration is sticking very close the nominal acceleration due to gravity of 9.8 (except for the spikes and fluctuations from me flipping the sensor).
The ability to reliably measure gravity from various orientations was very important in my specific application and this calibration technique should work very well for me and hopefully others having the same issue!