This field must be visible in the pivot table.

Excel formula: Get pivot table grand total

Excel formula: Get pivot table subtotal grouped date

Excel GETPIVOTDATA function