diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php
index 2beed2f0dc..78aca29867 100644
--- a/pandora_console/include/functions_inventory.php
+++ b/pandora_console/include/functions_inventory.php
@@ -818,9 +818,16 @@ function inventory_get_datatable(
 
 function get_data_basic_info_sql($params, $count=false)
 {
+    $table = 'tagente';
+    if (is_metaconsole() === true) {
+        $table = 'tmetaconsole_agent';
+    }
+
     $where = 'WHERE 1=1 ';
-    if ($params['id_agent'] > 0) {
+    if ($params['id_agent'] > 0 && $count === true) {
         $where .= sprintf(' AND id_agente = %d', $params['id_agent']);
+    } else if ($params['id_agent'] > 0 && $count === false) {
+        $where .= sprintf(' AND %s.id_agente = %d', $table, $params['id_agent']);
     }
 
     if ($params['id_group'] > 0) {
@@ -897,11 +904,6 @@ function get_data_basic_info_sql($params, $count=false)
     $innerjoin = '';
     $groupby = '';
 
-    $table = 'tagente';
-    if (is_metaconsole() === true) {
-        $table = 'tmetaconsole_agent';
-    }
-
     if ($count !== true) {
         $fields = '*';
         $innerjoin = 'LEFT JOIN tagente_estado ON '.$table.'.id_agente = tagente_estado.id_agente ';
diff --git a/pandora_console/operation/inventory/inventory.php b/pandora_console/operation/inventory/inventory.php
index a402444fff..d706221db2 100755
--- a/pandora_console/operation/inventory/inventory.php
+++ b/pandora_console/operation/inventory/inventory.php
@@ -1041,9 +1041,9 @@ if ($inventory_module !== 'basic') {
         <?php
         if ($order_by_agent === true) {
             foreach ($rows as $agent_rows) {
-                $data = [];
                 $modules = '';
                 foreach ($agent_rows['row'] as $key_row => $row) {
+                    $data = [];
                     $columns = explode(';', io_safe_output($row['data_format']));
                     array_push($columns, 'Timestamp');