Skip to main content
Solved

CONTIF equivalent function in FME

  • October 6, 2017
  • 5 replies
  • 221 views

Is there any transformer equivalent to COUNTIF or COUNTIFS excel functions in FME.

I have a very large csv file that is not openable in excel that i need to perform a count on certain attributes that have numerical values. e.g Count the total number of values between 1-10 etc

I am currently using expressionevaluator transformer where it sets an attribute to 1 if condition is met otherwise 0. then i use statistics calculator to sum up the total.

wondering if there is any quick and simple way to do that.

I have two attributes that i need to check with 5 different conditions

Best answer by takashi

I think your approach (add attributes storing 1 or 0 that indicates whether the row matches a condition and then sum up them with a StatisticsCalculator) is enough simple. If you want to reduce the number of transformers, consider using an AttributeCreator or AttributeManagure with conditional value setting to create the flag attributes for every condition, rather than using ExpressionEvaluators. You can then set the attributes to the Attributes to Analyze parameter in the StatisticsCalculator.

Alternatively, if you are familiar with SQL syntax, the InlineQuerier with a SQL query that counts the number of rows matching each condition could also be a solution. The SQL query would look like this.
select
(select count(*) from source where <condition 1>) as count1,
(select count(*) from source where <condition 2>) as count2,
...
(select count(*) from source where <condition 10>) as count10

Note: Querying itself would be very fast, but the InlineQuerier takes creates a temporary SQLite database that stores entire source dataset, and it takes a certain time. I'm not sure it would be more efficient than the StatisticsCalculator approach when the number of rows from the CSV table is very large.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

redgeographics
Celebrity
Forum|alt.badge.img+60
  • Celebrity
  • 3704 replies
  • October 6, 2017

A StatisticsCalculator, set to group by the attribute you're analysing, should do the trick.


takashi
Celebrity
  • 7843 replies
  • Best Answer
  • October 8, 2017

I think your approach (add attributes storing 1 or 0 that indicates whether the row matches a condition and then sum up them with a StatisticsCalculator) is enough simple. If you want to reduce the number of transformers, consider using an AttributeCreator or AttributeManagure with conditional value setting to create the flag attributes for every condition, rather than using ExpressionEvaluators. You can then set the attributes to the Attributes to Analyze parameter in the StatisticsCalculator.

Alternatively, if you are familiar with SQL syntax, the InlineQuerier with a SQL query that counts the number of rows matching each condition could also be a solution. The SQL query would look like this.
select
(select count(*) from source where <condition 1>) as count1,
(select count(*) from source where <condition 2>) as count2,
...
(select count(*) from source where <condition 10>) as count10

Note: Querying itself would be very fast, but the InlineQuerier takes creates a temporary SQLite database that stores entire source dataset, and it takes a certain time. I'm not sure it would be more efficient than the StatisticsCalculator approach when the number of rows from the CSV table is very large.


  • Author
  • 17 replies
  • October 11, 2017

I think your approach (add attributes storing 1 or 0 that indicates whether the row matches a condition and then sum up them with a StatisticsCalculator) is enough simple. If you want to reduce the number of transformers, consider using an AttributeCreator or AttributeManagure with conditional value setting to create the flag attributes for every condition, rather than using ExpressionEvaluators. You can then set the attributes to the Attributes to Analyze parameter in the StatisticsCalculator.

Alternatively, if you are familiar with SQL syntax, the InlineQuerier with a SQL query that counts the number of rows matching each condition could also be a solution. The SQL query would look like this.
select
(select count(*) from source where <condition 1>) as count1,
(select count(*) from source where <condition 2>) as count2,
...
(select count(*) from source where <condition 10>) as count10

Note: Querying itself would be very fast, but the InlineQuerier takes creates a temporary SQLite database that stores entire source dataset, and it takes a certain time. I'm not sure it would be more efficient than the StatisticsCalculator approach when the number of rows from the CSV table is very large.

Thanks @takashi the attribute create method is quicker. However I want to try the inline querier, but for some reason its not generating any output. can you provide an example workbench if possible.

 


takashi
Celebrity
  • 7843 replies
  • October 11, 2017

I think your approach (add attributes storing 1 or 0 that indicates whether the row matches a condition and then sum up them with a StatisticsCalculator) is enough simple. If you want to reduce the number of transformers, consider using an AttributeCreator or AttributeManagure with conditional value setting to create the flag attributes for every condition, rather than using ExpressionEvaluators. You can then set the attributes to the Attributes to Analyze parameter in the StatisticsCalculator.

Alternatively, if you are familiar with SQL syntax, the InlineQuerier with a SQL query that counts the number of rows matching each condition could also be a solution. The SQL query would look like this.
select
(select count(*) from source where <condition 1>) as count1,
(select count(*) from source where <condition 2>) as count2,
...
(select count(*) from source where <condition 10>) as count10

Note: Querying itself would be very fast, but the InlineQuerier takes creates a temporary SQLite database that stores entire source dataset, and it takes a certain time. I'm not sure it would be more efficient than the StatisticsCalculator approach when the number of rows from the CSV table is very large.

I would provide an example if you could share a sample data here.

  • Author
  • 17 replies
  • October 17, 2017

I think your approach (add attributes storing 1 or 0 that indicates whether the row matches a condition and then sum up them with a StatisticsCalculator) is enough simple. If you want to reduce the number of transformers, consider using an AttributeCreator or AttributeManagure with conditional value setting to create the flag attributes for every condition, rather than using ExpressionEvaluators. You can then set the attributes to the Attributes to Analyze parameter in the StatisticsCalculator.

Alternatively, if you are familiar with SQL syntax, the InlineQuerier with a SQL query that counts the number of rows matching each condition could also be a solution. The SQL query would look like this.
select
(select count(*) from source where <condition 1>) as count1,
(select count(*) from source where <condition 2>) as count2,
...
(select count(*) from source where <condition 10>) as count10

Note: Querying itself would be very fast, but the InlineQuerier takes creates a temporary SQLite database that stores entire source dataset, and it takes a certain time. I'm not sure it would be more efficient than the StatisticsCalculator approach when the number of rows from the CSV table is very large.

Due to the large dataset the inline querier takes almost similar times as compared to AttributeCreater method with conditional value setting then using the statisticscalculator to do the sum. however the sql query takes no time.

 

Thanks,