# Assistance with Transposing Excel Data

**URL:** <https://forum.knime.com/t/assistance-with-transposing-excel-data/84191>\
**Category:** KNIME Analytics Platform\
**Created:** [October 30, 2024, 11:18pm UTC](https://forum.knime.com/t/assistance-with-transposing-excel-data/84191 "2024-10-30T23:18:16Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![MRWA4687](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/m/aca169/32.png) [@MRWA4687](https://forum.knime.com/u/MRWA4687)\
**Post date:** [October 30, 2024, 11:18pm UTC](https://forum.knime.com/t/assistance-with-transposing-excel-data/84191/1 "2024-10-30T23:18:16Z")

</div>

Hi All

First time poster but long time reader of the forum and the great wisdom it contains.

I am having some issues developing a fairly simple workflow to deal with some traffic data.

Unfortunately the data is not provided in a consistent format so column headers change and there are blank columns in some of the supplied data.

The workflow needs to simply opens all of the spreadsheets matching the filter and then writes then in a single workbook with a sheet for the AM peak, PM peak and 24 hour volumes.

The data is split into a pattern of 13 columns that provide information on different vehicles. Each pattern represents a “movement” e.g. the first one is the left turn, the second the through movement etc.

Refer to sample below:

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/6/4/644f37c3101b7d29d11ded9da4e3fe121c88151c.png)

And this needs to be changed to:

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/e/4/e4095215d96887b9251f3fafe401246692aacc95.png)

For future manipulation outside of KNIME I need to transpose the 13 columns for each movement into a single row which means for each intersection there could possibly be up to 12 rows.

I have used loops to read in different part of the spreadsheet to identify each “movement” but not all movements are appearing in the output and I am getting an error with the writing of the data within the loop with the message file in use.

Extracts of workflow  
Step 1 opens all of the files and creates a single excel file with a sheet for AM, PM and 24 hours counts.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/c/7/c79ab1103676ec7ac19ad18d03660614523ac88a.png)

Step 2 – reconfigure the data  
The problem workflow. This reads in different parts of the Excel workbook i.e. in 13 columns chunks and writes it out.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/e/f/efee3fcfa7def664d3d16a137deffb497e3f5288.png)

The looping part is not working correctly. If I move the writing of the Excel file to outside of the loop the data is not written in 13 columns it is “staggered” as per the original location of the data.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/4/d/4d9be7adbf9a61d197a3a7ef86665cadef63903a.png)

Any suggestions on how to overcome this issue or a different approach? Is there a setting I am missing in the Excel writer?

I am sure that there is a simple solution to this but I am yet to find it and I have searched the forums.

Thanks for any assistance.

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [October 30, 2024, 11:52pm UTC](https://forum.knime.com/t/assistance-with-transposing-excel-data/84191/2 "2024-10-30T23:52:52Z")

</div>

@MRWA4687 here is an example where trips are identified based on rules

> [@Label data rows based on column values & calculate measures for each label group](https://forum.knime.com/t/label-data-rows-based-on-column-values-calculate-measures-for-each-label-group/82785/6):
>
> @Er3n you could take a look at this example trying to identify the trips The relevant Column Expression goes like this: if (equals(column("Counter"),1) && // && means AND ( isMissing(column("Status")) || isNaN(column("Status")) // || means OR ) && equals(column("Total cumulated distance"), 0) ) {column("rank")} else {toNull("")}

If you have a way of finding the start or end of you blocks you can mark them by this and handle them in a loop

> [@Move head rows to a column](https://forum.knime.com/t/move-head-rows-to-a-column/45094/2):
>
> @willy_oracle typically you would mark all lines with a [Counter](https://kni.me/n/pVT_aAQrO1Jkt9cG). Then identify the ‘headers’ with a rule engine [IF Col1 LIKE “Head\*” =\> Counter] and keep that (starting) row in a separate column. Then you [fill the missings with the previous value](https://forum.knime.com/t/replace-placeholder-with-values-from-above/38602/4) so a block would emerge marking the data table: [image] So now you have the blocks marked an can use a [Table Row to Variable Loop Start – KNIME Community Hub](https://kni.me/n/q7loejCZ1HWH5hUr) or [Group Loop Start – KNIME Community Hub](https://kni.me/n/7a8fxq51Z1jrgXeM) to do something with the blocks (export them delet…

To close a loop you can collect the results with a loop end.

---

<div class="post-metadata">

**Author:** ![MRWA4687](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/m/aca169/32.png) [@MRWA4687](https://forum.knime.com/u/MRWA4687)\
**Post date:** [October 31, 2024, 6:01am UTC](https://forum.knime.com/t/assistance-with-transposing-excel-data/84191/3 "2024-10-31T06:01:03Z")

</div>

Thanks for the response. My issue is not with the finding of the blocks I know where they are but the problem is writing them. I cannot seem to get the data aligned in an output that contains 13 columns and 1 row for each movement as opposed to the original input which contains one row with 13 columns x 12 (one for each movement).

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [October 31, 2024, 6:07am UTC](https://forum.knime.com/t/assistance-with-transposing-excel-data/84191/4 "2024-10-31T06:07:11Z")

</div>

@MRWA4687 maybe you can concatenate the data?

> **[Concatenate](https://hub.knime.com/knime/extensions/org.knime.features.base/latest/org.knime.base.node.preproc.append.row.AppendedRowsNodeFactory)**
>
> This node concatenates two tables. The table at inport 0 is given as the first input table (top input port), the table at inport 1 is the second table, resp. C…

Also maybe it is best to explicitly wire the writer to the loop end or if the loop is still collecting the data to have this as the last step?

---

<div class="post-metadata">

**Author:** ![MRWA4687](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/m/aca169/32.png) [@MRWA4687](https://forum.knime.com/u/MRWA4687)\
**Post date:** [October 31, 2024, 6:55am UTC](https://forum.knime.com/t/assistance-with-transposing-excel-data/84191/5 "2024-10-31T06:55:13Z")

</div>

The loop is still collecting the data. The concatenate does not resolve the issue.

Thanks for the suggestions.

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [October 31, 2024, 7:07am UTC](https://forum.knime.com/t/assistance-with-transposing-excel-data/84191/6 "2024-10-31T07:07:18Z")

</div>

@MRWA4687 I think you will have to plan out what you want to do at each step … you could also provide an example with dummy data for us to take a look.

---

<div class="post-metadata">

**Author:** ![MRWA4687](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/m/aca169/32.png) [@MRWA4687](https://forum.knime.com/u/MRWA4687)\
**Post date:** [October 31, 2024, 7:25am UTC](https://forum.knime.com/t/assistance-with-transposing-excel-data/84191/7 "2024-10-31T07:25:46Z")

</div>

Noted. However, I thought that I had done that in my original post where I provide snapshots of the data (and the workflows) as is as well as showing how it needs to be reformatted. Is this not visible or able to be followed?

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [October 31, 2024, 8:13am UTC](https://forum.knime.com/t/assistance-with-transposing-excel-data/84191/8 "2024-10-31T08:13:53Z")

</div>

@MRWA4687 It would be best to provide a real example. Screenshots are nice but only go so far as to work on a problem.

---

<div class="post-metadata">

**Author:** ![MRWA4687](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/m/aca169/32.png) [@MRWA4687](https://forum.knime.com/u/MRWA4687)\
**Post date:** [October 31, 2024, 10:19pm UTC](https://forum.knime.com/t/assistance-with-transposing-excel-data/84191/9 "2024-10-31T22:19:22Z")

</div>

Hi

I have attached 2 files - **Sample Data.xlsx** this is the data after is extracted from the various spreadsheets. This is the data that needs to be transposed and the 19 columns written in a row for each movement.  
[Sample Data.xlsx](https://forum.knime.com/uploads/short-url/1m3yIoJdGecLiS9CNwe1x6jc507.xlsx) (25.0 KB)

**Wanted Output.xlsx** - this shows the data reformatted for Intersection 1 for the 12 movements and movement 1 for Intersection 2. The pattern then continues.  
[Wanted output.xlsx](https://forum.knime.com/uploads/short-url/fusm4CSBcPIAaMldBvv1aYnm8tD.xlsx) (10.4 KB)

The issue I am struggling with is getting the output written the way shown in the spreadsheet Wanted Output.

Thanks for any assistance.

---

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [November 1, 2024, 3:54pm UTC](https://forum.knime.com/t/assistance-with-transposing-excel-data/84191/10 "2024-11-01T15:54:37Z")

</div>

@MRWA4687 so with the sample I think I was able to put together a workflow that can demonstrate how this could be done. It involves several small steps to bring the data in the right shape at several points.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/f/5/f573662efdab5944e3806c22b290148d257c87f1.png)

I might add some further explanations down the road. Maybe you take a look.

> **[Transform Movement Data - KNIME Forum (84191) – mlauber71](https://hub.knime.com/mlauber71/spaces/Forum/2024/Transform%20Movement%20Data%20-%20KNIME%20Forum%20(84191)~PT-uDxEi_fGTfH_z/current-state)**
>
> KNIME Forum question (84191) about the transformation of movement data from wide columns to fixed fields

---

<div class="post-metadata">

**Author:** ![MRWA4687](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/m/aca169/32.png) [@MRWA4687](https://forum.knime.com/u/MRWA4687)\
**Post date:** [November 2, 2024, 7:56am UTC](https://forum.knime.com/t/assistance-with-transposing-excel-data/84191/11 "2024-11-02T07:56:35Z")

</div>

Thankyou for the suggested workflow.

I am not familar with some of those nodes and I will work my way through the suggested workflow and see if I can implement it. If I have any queries I will come back to you.

Thanks again.

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [January 31, 2025, 7:56am UTC](https://forum.knime.com/t/assistance-with-transposing-excel-data/84191/12 "2025-01-31T07:56:49Z")

</div>

Closed on January 31, 2025, 7:56am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
