# Error reading table precio with table handler amplxl:

**URL:** <https://discuss.ampl.com/t/error-reading-table-precio-with-table-handler-amplxl/1210>\
**Category:** Support\
**Tags:** general, errors-and-messages\
**Created:** [September 13, 2024, 1:42am UTC](https://discuss.ampl.com/t/error-reading-table-precio-with-table-handler-amplxl/1210 "2024-09-13T01:42:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laura\_Rodriguez](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/laura_rodriguez/32/831_2.png) [@Laura\_Rodriguez](https://discuss.ampl.com/u/Laura_Rodriguez)\
**Post date:** [September 13, 2024, 1:42am UTC](https://discuss.ampl.com/t/error-reading-table-precio-with-table-handler-amplxl/1210/1 "2024-09-13T01:42:14Z")

</div>

Hello. Hope you all doing well.

Im using Excel to read data in AMPL and Im trying to read this next table that I called “precio” but im not being able to put the correct comands to make this possible.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/ampl/original/1X/213459043efc8e32be96a6a24bb874f594587645.png)

That table depends of g and t01 …t024 (T) and those parameters are used in other different tables

however, g and T in other tables have unique data that is not the same from the table “precio”.

but all of the information has some correlation

hope someone can help 🙂 thx

---

<div class="post-metadata">

**Author:** ![Nicolau\_Santos](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/nicolau_santos/32/61_2.png) [@Nicolau\_Santos](https://discuss.ampl.com/u/Nicolau_Santos)\
**Post date:** [September 14, 2024, 3:24am UTC](https://discuss.ampl.com/t/error-reading-table-precio-with-table-handler-amplxl/1210/2 "2024-09-14T03:24:30Z")

</div>

Hi @Laura_Rodriguez

I didn’t fully understand the issue with g and T.  
If possible, I’ll ask you to post a minimal working example of the issues you are facing.  
Otherwise please post the contents of one of the other tables that is also indexed by g and T, the AMPL declarations of those sets and the corresponding interpretation of those sets in your model, as you might not be using the g and T sets but only some subsets of them.

---

<div class="post-metadata">

**Author:** ![Laura\_Rodriguez](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/laura_rodriguez/32/831_2.png) [@Laura\_Rodriguez](https://discuss.ampl.com/u/Laura_Rodriguez)\
**Post date:** [September 14, 2024, 7:05pm UTC](https://discuss.ampl.com/t/error-reading-table-precio-with-table-handler-amplxl/1210/3 "2024-09-14T19:05:36Z")

</div>

Hi,  
table 1

 ![image](https://us1.discourse-cdn.com/flex019/uploads/ampl/original/1X/9a891fde158681e33b09d9a1c71b8f43da8e59c0.png)

The first table depends on the parameters T and D, where T stands for time and D stands for demand. The second table also includes the parameter G, which stands for generator.

For example:

- At time **t01** , producing from generator **g1** costs **13.32**. (from first table i ever shared)
- The same generator, **g1** , has a certain power capacity (as shown in Table 2).
- At the same time **t01** , demand **D1** requires **67.48173** units (as shown in Table 1).

_but im not being able to read the first table i ever shared_

so far im using this writing to read table 1 and table 2:

.run:

table Tiempo IN “amplxl” “DTU-Perfiles1.xlsx” “periods”:

T ← [T];

read table Tiempo;

#------------------------------------------------------------------------------

table Generacion IN “amplxl” “dtu.xlsx” “gen”:

[G] IN, pmax,pmin;

table Demandas IN “amplxl” “dtu.xlsx” “dem”:

[D] IN, dem;

table Perfil\_Demandas IN “amplxl” “DTU-Perfiles1.xlsx” “dem” “2D”:

[D, T], prfl\_dem;

table GeneracionCX IN “amplxl” “dtu.xlsx” “gen”:

Gn ← [G, B];

table DemandaCX IN “amplxl” “dtu.xlsx” “dem”:

Dn ← [D, B];

.mod:

set T ordered ; # periodos

set B default {} ; # barras

set G ; # generadores  
set D ; # demandas

set Gn within {G, B} ; # conexion de generadores  
set Dn within {D, B} ; # conexion de demandas

set L dimen 2;  
set FROM = setof {(i,j) in L} j;  
set TO = setof {(i,j) in L} i;

# ----------------------------------------------------

param po {G, T} \>= 0 ; # precio de oferta  
param pmin {G} \>= 0 ; # potencia minima de generacion de cada G  
param pmax {G} \>= 0 ; # capacidad ofertada  
param fmax {L} \>= 0 ; # capacidad por linea  
param xlin {L} \>= 0 ; # reactancia de la linea

param dem {D} \>= 0 ; # potencia consumida  
param prfl\_dem {D, T} \>= 0 ; # perfil de demanda / dem

---

<div class="post-metadata">

**Author:** ![Laura\_Rodriguez](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/laura_rodriguez/32/831_2.png) [@Laura\_Rodriguez](https://discuss.ampl.com/u/Laura_Rodriguez)\
**Post date:** [September 14, 2024, 7:06pm UTC](https://discuss.ampl.com/t/error-reading-table-precio-with-table-handler-amplxl/1210/4 "2024-09-14T19:06:27Z")

</div>

table 2

 ![image](https://us1.discourse-cdn.com/flex019/uploads/ampl/original/1X/5aae473b3cd56b7d0dc4d435d6b1dc379d35b8bb.png)

---

<div class="post-metadata">

**Author:** ![Nicolau\_Santos](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/nicolau_santos/32/61_2.png) [@Nicolau\_Santos](https://discuss.ampl.com/u/Nicolau_Santos)\
**Post date:** [September 16, 2024, 8:29pm UTC](https://discuss.ampl.com/t/error-reading-table-precio-with-table-handler-amplxl/1210/5 "2024-09-16T20:29:26Z")

</div>

Hi @Laura_Rodriguez

Thank you for the provided information!

To load data from a table with one indexing set you just need the table declaration and the read command.  
However, when you load data from a table with more than one indexing set, the data from the indexing sets must be loaded before.

In the case of table `precio` you have two indexing sets, `G` and `T`, so you first need to load the data for `G` and `T` and only than you can read table `precio`

```auto
table Tiempo IN "amplxl" "dtu.xlsx" "periods":
	T <- [T];

table Generacion IN "amplxl" "dtu.xlsx" "gen":
	G <- [G], pmax, pmin;

table precio IN "amplxl" "dtu.xlsx" "2D":
	[G, T], po;

read table Tiempo;
read table Generacion;
read table precio;

```

As `precio` is a 2D table you need to put the name `G` on top of the column. From the table declaration amplxl will deduce that the header of the table has elements of `T` and that the parameter that you are reading is `po`.

A quick read to [this](https://discuss.ampl.com/t/amplxl-quick-example/317) post might help understanding how amplxl and 2D tables work. amplxl documentation is available [here](https://plugins.ampl.com/amplxl.html).

Sample files attached [example.zip](https://discuss.ampl.com/uploads/short-url/bPrvzPR6fZEiInVfKuAmaYhEC4j.zip) (9.4 KB) with minor changes but also loading the `prfl` data.
