0

Hi

I have database in structure like below

Newspaper State1 state2 state3 state4

ABC 1000 5684 5687 246
DEF 879 2547 2578 2357

But I need to the structure like below

How can i change this

Newspaper State copies

ABC State1 1000
ABC State2 5684
ABC State3 5687
ABC State4 246
DEF State1 879
DEF State2 2547
DEF State3 2578
DEF State4 2357

Pls help me

Maideen

3
Contributors
3
Replies
15
Views
3 Years
Discussion Span
Last Post by kgariando
0

here is the code

SELECT [NewsPaper]
      ,[State],[Copies]
FROM 
   (SELECT [NewsPaper]
      ,[State1]
      ,[State2]
      ,[State3]
      ,[State4]
   FROM [Test].[dbo].[News]) p
UNPIVOT
   (Copies FOR State IN 
      (State1,State2,State3,State4)
)AS unpvt;
GO
0

Step 1 Select the data and turn it into a table
Step 2 Select Power Query –> From Table to suck it in to Power Query
Step 3 Un-pivot it

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.