Problema planteado a partir de búsqueda con filtro / Problem raised from filter search - Forum

Forum Navigation
You need to log in to create posts and topics.

Problema planteado a partir de búsqueda con filtro / Problem raised from filter search

@vadim, @gaev, @asleycruzZ

ESPAÑOL:

Hola Gente, una vez más recurro a la comunidad para poder resolver un problema que se me presenta y que no puedo dar con la solución:

A partir de una base de datos que maneja una caja de cobros, tengo 3 campos fundamentales,  importe/comisiones/neto
todo funciona perfecto , hago una suma del campo importe y una suma del campo comisiones y luego la resta de ambos me da el neto... hasta ahí perfecto

 

Ahora el problema se me presenta cuando yo hago una búsqueda entre dos fechas, esto perfecto el problema es que cuando
me muestra en la grilla los resultados de los registros obtenidos los campos importe, comisiones y neto son de la base total
no del producto de la suma y resta de los registros mostrados

Existe alguna forma que pueda obtener esos registros y que los valores que muestren sea los que correspondan solo al rango de fecha encontrado?

ENGLISH

Hello People, once again I turn to the community to be able to solve a problem that appears to me and that I cannot find the solution:

From a database that manages a collection box, I have 3 fundamental fields, amount / commissions / net
everything works perfect, I do a sum of the amount field and a sum of the commissions field and then the subtraction of both gives me the net ... until there perfect

Now the problem arises when I do a search between two dates, this is perfect, the problem is that when
It shows me in the grid the results of the records obtained, the fields amount, commissions and net are from the total base
No. of the product of the addition and subtraction of the records shown

Is there a way that I can get those records and that the values they show are the ones that correspond only to the date range found?

 

 

 

@joferar333

If you are only storing the sum of fields for ALL records, there is no way to automatically get the sum for SELECTED records ... but you can recalculate the numbers more efficiently using SQL commands (via the dbpExecSQL command) ... for the SQL syntax, see ...

https://www.w3schools.com/sql/sql_count_avg_sum.asp

luishp has reacted to this post.
luishp

@vadim@gaev@asleycruz

Lamentablemente no me función

Como se puede apreciar en la foto ahi esta el resultado de una vista filtrada para obtener los datos de la caja del dia especifico

el problema que el saldo que me muestra es el total de toda la base todos los dias ingresados... cuando en realidad lo que tendria

que mostrar es la suma de la columna Neto... alguna idea?

As you can see in the photo, there is the result of a filtered view to obtain the data of the box for the specific day

the problem that the balance that shows me is the total of the entire base every day entered ... when in reality what I would have

to show is the sum of the Net column ... any ideas?

@vadim@gaev@asleycruz

currently adds the entire field, I can not find the formula to do what you tell me to make it add more efficiently

Hola @joferar333

Los ejemplos de abajo los probé funcionan bien. Si tengo toda la tabla abierta o si solo tengo 3 resultados, ambos muestran la suma correcta de los resultados visible en la tabla. No sé de qué forma estás haciendo la suma. OJO el campo precio está en tipo Number.

BUSCAR CON dbpQuery PRECIOS MAYORES A 7

dbpQuery "demo" "caja" "precio > 7"
dbpSum "demo" "caja" "precio" "[sumaTotal]"

 

BUSCAR CON dbpExecSQL PRECIOS MAYORES A 7

dbpExecSQL "demo" "SELECT * FROM caja WHERE precio > 7" ""
dbpSum "demo" "caja" "precio" "[sumaTotal]"

@asleycruz

Si es correcto tanto importe - comisiones - neto - saldo son campos numericos

Pero el tema que yo busco y filtro por fecha.

Ahi en la foto por ejemplo se filtro la base para que muestre solo los registros del dia 03 de noviembre

Ahora no me doy cuenta como implementar tu ejemplo en esto...
La idea es que al mostrar los registros filtrados  el saldo se corresponda con la suma del neto...

 

@joferar333

La vez pasada alguien te mandó el ejemplo sencillo de como buscar entre dos fechas. Si podes compartirme ese ejemplo para tratar de solucionarlo ya que no sé en qué foro está.

@asleycruz

Claro esto es lo que uso y funciona perfecto

dbpQuery "gestion" "caja" "Fecha BETWEEN #[desde]# AND #[hasta]#"

If "[gestion.caja.$RecCount]" "=" "0"
AlertBox "Datos" "No hay ningún registro."
dbpShowAll "gestion" "caja"
EndIf

@asleycruz

I might be losing something in the translation but as far as I can tell, @joferar333 wants a running total in the column/field titles Saldo ... something that is common in Spreadsheets (Excel, Google etc.) ... databases do not work like that (even if the Grid displays makes it look like a spreadsheet).

@joferar333 - the best you can do is use the SQL commands I mentioned to show the Totals (for the selected date range) for each of Importe, Comisiones, Neto and Saldo ... just one value for each field ... shown in a separate box outside the Grid.

Otherwise, you would have to calculate/update the values for each row in the selected range ... something that can take a long time when the resulting number of rows is too large.

AsleyCruz has reacted to this post.
AsleyCruz

@joferar333

Pues la verdad deberías revisar bien la base de datos/variables/campos, ya que probé con tu código y funcionó bien, busqué entre varias fechas, me mostró 2 resultados de 7, y dbpSum hizo la suma correspondiente. Nunca sumó todos los registros de la tabla, sino solamente los registros visibles después de la búsqueda :/

dbpSum "gestion" "caja" "neto" "[sumaTotal]"

@asleycruz

Si Asley tenias razon...

Ya me funciona perfecto

MIL MIL GRACIAS

@joferar333

Please create a demo file illustrating the problem in cases like this, so we can understand the question faster and give an answer. The automatic text translation in your browser is not yet perfect, so a lot gets lost. In addition, the initial version of the file (with the question) and the final version of the file (with the answer) will enable other users to quickly solve the problem if they have it.

 

 

luishp and CN_Iceman have reacted to this post.
luishpCN_Iceman