Hello,
While creating dynamic pivot table, in the code part where column names are generated, you can use a where criteria preventing null values to be displayed as column header.
If you check the dynamic sql pivot table example, you can add a similar where clause where column headers are concatenated
DECLARE @PivotColumnHeaders VARCHAR(MAX)
SELECT @PivotColumnHeaders =
COALESCE(
@PivotColumnHeaders + ',[' + cast(Category as varchar) + ']',
'[' + cast(Category as varchar)+ ']'
)
FROM (
SELECT Distinct Category FROM UserData where value is not null
) u
SELECT @PivotColumnHeaders
Here the "value" column is the aggregated column in the pivot