Skip to main content

Hi,

It’s been several times I can’t achive to do this, but I’m sure there is a way.

I have the following table :

And I want to get the following result :

 

The thing is : I don’t know in advance what will be the name of IndA and IndB (and there can be more than 2 values, so more than 2 columns in the result table).

 

I achieved to get my result table with an inlineQuerier, but I need to enter a fixed value for the Indicateur values.

select "Zone",
max(CASE WHEN "Indicateur"='IndA' THEN Valeur ELSE 0 END) as 'IndA',
max(CASE WHEN "Indicateur"='IndB' THEN Valeur ELSE 0 END) as 'IndB'
from "Input"
GROUP BY "Zone"

 

Any idea ?

Can’t find how to edit my first message :(

The first table has disappeared when posting, so I put it here.

This is the input data :

 


Can’t find how to edit my first message :(

 

Since we migrated to the new community platform, time to edit is limited to something like 30 minutes.

Hi,

It’s been several times I can’t achive to do this, but I’m sure there is a way.

I have the following table :

And I want to get the following result :

 

The thing is : I don’t know in advance what will be the name of IndA and IndB (and there can be more than 2 values, so more than 2 columns in the result table).

 

I achieved to get my result table with an inlineQuerier, but I need to enter a fixed value for the Indicateur values.

select "Zone",
max(CASE WHEN "Indicateur"='IndA' THEN Valeur ELSE 0 END) as 'IndA',
max(CASE WHEN "Indicateur"='IndB' THEN Valeur ELSE 0 END) as 'IndB'
from "Input"
GROUP BY "Zone"

 

Any idea ?

This can be done by simply using an attributecreator like this:

And then merge the rows into one using an Aggregator like this:

But as these attributes are created at runtime, workbench can not know what they are. They are unexposed. But you can see the values in the Feature Information window:

 

So the question is, what do you want to do with the data after transposing?

If you want to simply write the transposed data to a table, write it using a dynamic workflow. One way to do this is to use a SchemaScanner transformer to create a Schema Feature and use that as input for a dynamic FeatureWriter.

If you want to do something with the transposed data in the workflow, downstream the transpose action, you will need to expose the created attributes using an AttributeExposer.

 

===============

 

Attached sample workspace demonstrating this.

 


Thank you @nielsgerrits for your detailed answer !

 

My goal is to write the data in an Excel file.


In the meantime, I achieved to do what I want with nearly the steps you mention, not being sure it was a great solution.

 

I used the AttributeCreator and then the Aggregator and get my attributes per Zone (unexposed).

 

Then I used the ExcelWriter with dynamic schema.

My issue was “how to create the destination schema ?”. I achieved to do so with a ListBuilder : creation of an attribute{} list with name and fme_data_type.

SchemaScanner is not available in FME 2020 that I still use, but it seems and interesting solution, I’ll give it a try.

I still had the issue that my Zone attribute, that I let in the User attributes tab of the ExcelWriter, was written as the last column in Excel file.
I added a attribute{0} with name Zone in the schema, and it solved my issue.

 

So this seems to be the right solution to do it, and maybe simpler with SchemaScanner starting with FME 2022.


Correct, this is the same workflow. Using the SchemaScanner has the same result as the workflow you created.


Great solution!


Reply