Query to change format of table - field value to columns (new fields)

Dear all,

I have a table in the below format:

M      Y      District      Role      CountOfRole
1      2010      18      Admin      1
1      2010      19      IT      1
2      2010      18      Admin      2
2      2010      19      IT      1


I need to change the format to:

M      Y      District      Admin      IT
1      2010      18      2      1
2      2010      19      1      1

Is this possible in a query? Apologies for the alignment of example data.
AndyC1000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Deepak LakkadCommented:
Hi,

Yes, you can do it with Cross Tab Query.

In Access, there is an option for creating Cross Tab Query in Query Wizard.



- Deepak Lakkad
0
AndyC1000Author Commented:
Could you provide an example?
0
AndyC1000Author Commented:
I've tried to use the cross tab query wizard, the issue I'm having is at the 'what number do you want calculated for each column and row intersection.  I've selected the field 'CountOfRole' and I'm not sure which option to select - avg, count, var, first etc.
0
SharathData EngineerCommented:
Can you try this?
SELECT M,Y, 
       MIN(District)                         AS district, 
       MAX(IIF(Role = 'Admin', CountOfRole)) AS admin, 
       MAX(IIF(Role = 'IT', CountOfRole))    AS it 
  FROM your_table 
 GROUP BY M,Y 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.