How to give two column pivot

I Have table like

Position Actual_All LA_Adj SBU Final_Count LA_Date
DSE 4 0 XYZ 4 31-05-2023
SMT 3 0 XYZ 3 31-05-2023
IDSS 20 0 XYZ 20 31-05-2023
DSE 20 0 XYZ 20 01-06-2023
SMT 20 0 XYZ 20 01-06-2023
IDSS 20 0 XYZ 20 01-06-2023

but i need ouput like below.

May Jun
Row Labels Sum of Actual_All Sum of LA_Adj Sum of Final_Count Sum of Actual_All Sum of LA_Adj Sum of Final_Count
DSE 4 0 4 20 0 20
IDSS 20 0 20 20 0 20
SMT 3 0 3 20 0 20
Grand Total 27 0 27 60 0 60

Please give me an idea how to achive in select query in SQL server

This will be rather complicated to do in T-SQL. Suggest you read this for some examples:

Also note that SQL does not have any layout capability like merged cells for headers. If that is going to be important to you, you'll need to do this in a reporting tool like SSRS or an Excel Pivot Table.

You might also want to read Itzik's article on pivoting and unpivoting with CROSS APPLY:

Because you are pivoting on multiple columns, you may find it easier to UNPIVOT Actual_All, LA_Adj, and Final_Count into a Category column, with each value on separate rows, then SUM() their values and GROUP BY Month and Category. You would then concatenate Month and Category when you do the final pivot.

I apologize for not having an example, I haven't done multi-column pivoting in SQL in a while, I just put it into Excel when I need it.

1 Like