Take a look at the GETPIVOTDATA function.