I am trying to use the raw data from the 3-axis digital magnetic sensor (IIS2MDC) to get a compass heading, but cannot get it to work.
With the STWINBX1 flat on a table, I slowly rotated it 360 degrees starting from north.
I then exported the data and used the following formula to calculate the heading...

The result shows a heading between 285 degrees to 344 degrees (instead of a full 360 degree swing)...

The raw data looks like this...

Spreadsheet iis2mdc.xlsx is attached for reference.