# How to calculate minimum value and maximum value of «Concepto» of «Comercio Exterior» complement of Cfdi in USD.

In this post, I am going to explain how to calculate the maximum and minimum values of «Concepto» Node ​​for the «ComercioExterior» complement 1.1.

### Things you should know before.

• This post was written on March 3, 2020, to verify that the validation rules are still in force in Anexo 20.
• The post deals with the CCE205 rule, only the calculation of minimum and maximum values ​​of the Concept node.
• If you need to consult the CCE216 rule you can consult this post.
• The «ComercioExterior» complement is always expressed in USD.
• I will not use conversions between units of measurement.
• The decimal numbers used for rounding are 2 in USD.

### Example case:

I’m going to use the following Cfdi for the tutorial:

### Performing the calculation of limits:

I have coded a small console application to calculate the example along with the source code of the utility class. The program takes the fixed inputs, it does not read the example file. You must be careful with the method you choose to read the file, if you take the data from the Cfdi through serialization, the number of decimals may not match the original document. For example, 18.9000 in the cfdi can return 18.9 in decimal or double object, for the program, it is the same value, not for the formulas.

### What steps do I follow to calculate?

1. Iterates in the nodes «Concepto» of the Cfdi.
2. For each «Concepto» node. Obtain all «mercancia» nodes that have the same Identification Number as the concept (excluding those with «ValorDolares» ​​at 0 and 1).
3. In the case that there are no valid «mercancia» nodes, go to the next «Concepto» node.
4. Iterate all the Cfdi «Concepto» nodes and obtain the sum of the «Importe» values of all concepts field with the same Identification Number as the current concept (2 or more «Concepto» nodes may have the same identification number and two or more «mercancia» nodes can have the same identification number).
5. Get the «TipoCambio» value of the Cfdi (if the Cfdi was issued in MXN, this value may not exist, you should use 1 instead).
6. Get the «TipoCambioUSD» value from the «ComercioExterior» complement.
7. Obtain the number of decimals from the sum of Concept Amounts (Step 4).
8. Get the number of decimals of the «TipoCambio» value of the Cfdi (if the Cfdi was issued in MXN, this value may not exist, you must use 2 instead).
9. Get the number of decimals for the «TipoCambioUSD» value.
10. Run the calculation of minimum value and maximum value.
11. Round the values ​​and maximums according to the Currency used in the Cfdi.
12. Check the amount of «ValorDolares» that is equal to the Sum of the «ValorDolares» fields of the «mercancia» nodes with the same «NumeroIdentificacion» (some PACs calculate the «ValorDolares» field by multiplying the field «CantidadAduana» * «ValorUnitarioAduana» for each node «mercancia»).
13. Verify that the «ValorDolares» amount is within the maximum and minimum value.

### Points to consider.

The calculation of minimum and maximum values ​​may vary depending on the programming language you use, the type of data or the precision of the calculations, this is more evident when you handle numbers with many decimals.

### References:

Últimas entradas de Gustavo Sánchez (ver todo)

### Gustavo Sánchez

Soy especialista en escribir software de calidad. Mediante el uso de marcos de trabajo, técnicas y automatización de procesos he podido reducir los costes operativos de los sistemas de la empresa. Sistemas confiables y adaptables producen clientes felices.