Hi
I have below data
| Item | Amount | Catg |
| A001 | 100 | Accounts |
| A002 | 200 | Accounts |
| A002 | 400 | Accounts |
| A003 | 600 | Hr |
| A004 | 800 | Sales |
I want ti display like it below
| Item | Amount | Accounts | HR | Sales |
| A001 | 100 | 100 | ||
| A002 | 200 | 600 | ||
| A003 | 600 | 600 | ||
| A004 | 800 |
800 |
Thanks
Hi
I have below data
| Item | Amount | Catg |
| A001 | 100 | Accounts |
| A002 | 200 | Accounts |
| A002 | 400 | Accounts |
| A003 | 600 | Hr |
| A004 | 800 | Sales |
I want ti display like it below
| Item | Amount | Accounts | HR | Sales |
| A001 | 100 | 100 | ||
| A002 | 200 | 600 | ||
| A003 | 600 | 600 | ||
| A004 | 800 |
800 |
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh KumarPosted Mar 5, 2025, 12:33 PM
Hello Ramco,
instead of STRING_AGG() function you can use STUFF() in SQL 2014.
Ramco RamcoPosted Mar 5, 2025, 10:58 AM
Hi Jignesh
Below is the code. I need it in Sql 2014
Thanks
Jignesh KumarPosted Mar 5, 2025, 9:21 AM
Hello Ramco,
You can create dynamic pivot table to get requested data as below,
Ramco RamcoPosted Mar 5, 2025, 8:13 AM
Hi
Columns like Accounts , HR , Sales to be dynamic. There can be say another column to be added :Production"
Thanks
Daniel WrightPosted Mar 5, 2025, 7:51 AM
Hi there! It looks like you have a structured data table that you want to transform into a more organized format to display the information better.
In the initial table, each row represents an item with its corresponding amount and category. The goal is to pivot this data, so each category (Accounts, HR, Sales) has its column to showcase the total amount for each item under that category.
To achieve this, we can summarize the data by grouping it based on the categories and then aggregating the amounts. Here's a breakdown of how the transformation can be done:
1. A001:
- Accounts: $100
2. A002:
- Accounts: $600
3. A003:
- HR: $600
4. A004:
- Sales: $800
By restructuring the data this way, you can create a new table with columns for each category (Accounts**, **HR**, **Sales). Each item will then have its corresponding amount under the respective category heading, making it easier to analyze and understand the data at a glance.
You can use tools like Microsoft Excel, Google Sheets, or coding languages like Python with libraries such as Pandas to perform this data transformation. Let me know if you need further assistance with the implementation or have any specific questions. I'm here to help!