Question

How to group by based on multiple attributes?

  • 21 September 2021
  • 4 replies
  • 35 views

Hi everyone,

I just started out using FME Desktop for my job. I am trying to find out how it would be possible to use group by based on a combination of attributes. The example is just something I thought of, so not based on real data. Initially, the source data in this imaginary case would just have an overview of all the shops. First, I would like to have an overview of the amount of shops per mall. So first I have to group by based on which mall the shop does belong to. Thereafter I would like to group by based on what type of shop it is. E.g. Clothing store, ~department store etc. So for example from the 100 shops that belong to mall A 10 are clothing stores for example , 4 restaurants e.g. i tried it with the StatisticsCalculator, however when I put put all these attributes in the group by field, I don't get the result below. Instead of grouping first on the type of mall and thereafter looking at the type of shop, all attributes are considered in the grouping equally. So I got more rows. Does anyone know how I can get below result.Groupby_multiple_attributes


4 replies

Badge +20

I think you got the GroupBy function wrong.

When you "group by" FME searches for unique/identical values in that attribute/column and gives results for each "group" of unique values.

In the case of your imaginary data consisting of 2 totally unique rows GroupBy is useless.

Regarding getting your desired output please provide some sample data.

@caracadrian​  I am a little bit hesitant to share sample data. However, I guess I can share some samples. Actually in my case, it would be about districts and polling stations. I would like to know how many polling stations they are per district and per district how many polling stations are open on 15, 16 and 17 March respectively. First picture shows some sample source data, while the below picture shows the output I would like to achieve. Groupby_multiple_attributes2

Badge +20

@caracadrian​  I am a little bit hesitant to share sample data. However, I guess I can share some samples. Actually in my case, it would be about districts and polling stations. I would like to know how many polling stations they are per district and per district how many polling stations are open on 15, 16 and 17 March respectively. First picture shows some sample source data, while the below picture shows the output I would like to achieve. Groupby_multiple_attributes2

Now I understand the problem.

One solution is to map Ja to 1 using NullAttributeMapper

Map_Ja_to_1send that to a StatisticsCalculator with GroupBy District, Total Count on Location to get all the station in each district, and Sum on Open 15, Open 16 and Open 17 (we transformed every Ja to a 1 so we can sum😀 ).

StatisticsThis is just one solution, I like working with numbers and it avoids not NULL attributes (like Nee in just the Open 17 column as opposed to empty cells in 15 and 16).

Use AttributeManager to rename attributes according to your preferences.

Now I understand the problem.

One solution is to map Ja to 1 using NullAttributeMapper

Map_Ja_to_1send that to a StatisticsCalculator with GroupBy District, Total Count on Location to get all the station in each district, and Sum on Open 15, Open 16 and Open 17 (we transformed every Ja to a 1 so we can sum😀 ).

StatisticsThis is just one solution, I like working with numbers and it avoids not NULL attributes (like Nee in just the Open 17 column as opposed to empty cells in 15 and 16).

Use AttributeManager to rename attributes according to your preferences.

Thanks @caracadrian​ I have to say that this solution is quite nice. I didn't consider this approach, but it works really fine. With this approach in my case both Null values and Nee values are ignored.

Reply