How to merge tables at the end of an iteration?

880
15
10-05-2018 05:28 AM
SerenaFraccascia
New Contributor II

I am running a model iterating through N feature clases and I get N tables as output. The model works properly. Here it is:

I need to merge this tables into a new one, thus I would run my model as submodel. However, when I add it to the new model something goes wrong:

I am still learning modelling and programming skills, thus any help, suggestions, clarifications are more than welcome!

Tags (2)
0 Kudos
15 Replies
shan_sarkar
Regular Contributor

Serena,

 

I take it that both your models when executed individually work properly?

 

You can add the Model 1 and Model 2 in a new model with the Pre-Condition that model 1 should execute first and then invoke the second model. This should work in principle.

 

Integrating a model within a model—Help | ArcGIS Desktop 

 

Alternatively, you can run them as two separate models, but I doubt you want to execute the models particularly in that fashion. The best way to get this done will be to create a python script and execute which has the workflow lined up as per your requirement.

I hope this helps!

~Shan


~Shan
0 Kudos
SerenaFraccascia
New Contributor II

Thanks for your suggestion. The first model works properly and returns N output tables; if I apply the merge tool to the output tables it works, too, but for some reason I cannot combine the two into one model in order to automatize the process.

There was a similar question some time ago (Merge all iteration output to single output in modelbuilder), but it doesn't work either.

0 Kudos
shan_sarkar
Regular Contributor

The output tables from the first model do they have the same schema?

If they do you can simply use the Append—Help | ArcGIS Desktop  instead the merge. Maybe, the merge doesn't play well with the first half of the model. Besides append is the best way to go when it comes to merging data with same schema.

~Shan


~Shan
0 Kudos
DuncanHornby
MVP Frequent Contributor

You are almost correct. You have correctly identified that your main model with the iterator needs to be a sub-model in a model with a single Merge tool. Merge takes a LIST of inputs which you merge. So how do you create a LIST of tables? There is the model only COLLECTS VALUES tool. Tag that to the end of your output table IN you sub-model and expose it's output as a parameter. Drag that sub-model into a new model with just a merge tool and you will see that the sub model has a LIST output which simply connects to the input parameter of Merge.

SerenaFraccascia
New Contributor II

Thanks for your suggestion! It still doesn't work, as it seems that the fact that during the model the variable 'out_stats_%N%.dbf' is manipulated several times generates some kind of conflict when I run it as submodel. I cannot set them as intermediate variable (which I guess would solve the problem); I have read in some other post that that would be possible by setting the environment, but I am not so far with Model Builder and I would not know what to change. I would be very grateful if you could help me!

0 Kudos
DuncanHornby
MVP Frequent Contributor

You need to show us how you are running the summary statistics tool for anyone to comment. Add a screen shot of how the parameters have been set.

0 Kudos
SerenaFraccascia
New Contributor II

From the statistics I only need the mean value:

0 Kudos
DuncanHornby
MVP Frequent Contributor

What does %workspace% equate to, that could be the problem?

0 Kudos
SerenaFraccascia
New Contributor II

That's the workspace where the original tables are located.

0 Kudos