Graph with Top 5 and "Others" as Category (1 Viewer)

evillarrealca

New member
Local time
Today, 16:58
Joined
Mar 23, 2020
Messages
15
Hi, I'm building a graph after a Query that groups the Categories and Sums the amount for each category, the problem is that there are more than 10 categories, so I want to just graph the Top 5 and a new category named "Other" for the rest of the Income amount, so I can show a Pie Graph with the Top 5 and "Other" to have the 100% of Income in one Graph. Does any body have done this?
Thanks in advance for the help!
 

jdraw

Super Moderator
Staff member
Local time
Today, 17:58
Joined
Jan 23, 2006
Messages
15,379
For clarity, your Pie chart will have "6 slices", correct?
Some thoughts to consider:
T1,t2,t3,t4,t5,other
Other = Total-top5
Percentages
(Tx/total)*100 for x = 1-5
Other = 100 -( T1% +T2%.....+T5%)
 

evillarrealca

New member
Local time
Today, 16:58
Joined
Mar 23, 2020
Messages
15
Hi jdraw, that is correct, the pie will have 6 slices.
I got what you said but how do I write it into the query? or is it specified in the graph?
 

jdraw

Super Moderator
Staff member
Local time
Today, 17:58
Joined
Jan 23, 2006
Messages
15,379
I think you will need more than 1 query. I haven't done much with charts in quite a while.
I anticipate a Top5 query and another with all records not in Top5 as OTHER, then a union query as source for a chart, but it's been a while.
Can you post some sample data?
 

evillarrealca

New member
Local time
Today, 16:58
Joined
Mar 23, 2020
Messages
15
Attached is png of the query result (IncomeTable). That query is the one I used to build the Chart (IncomeChart).
 

Attachments

  • IncomeTable.png
    IncomeTable.png
    25.2 KB · Views: 194
  • IncomeChart.png
    IncomeChart.png
    17 KB · Views: 202

evillarrealca

New member
Local time
Today, 16:58
Joined
Mar 23, 2020
Messages
15
Hi jdraw, thanks for the tip but I've been having trouble to write the NOT IN query correctly. If you can help with this, here is the SQL query for the original Income query which has ALL the results:

SELECT tblTransacciones.tipoTran, Sum(tblTransacciones.montoTran) AS SumOfmontoTran, tblCuentas.nombreCuenta, tblBeneficiarios.idTpoBenef_FK, tblCuentas.idTipoCuenta_FK
FROM tblBeneficiarios INNER JOIN (tblCuentas INNER JOIN tblTransacciones ON tblCuentas.idCuenta = tblTransacciones.cuentaTran_FK) ON tblBeneficiarios.idBeneficiario = tblTransacciones.benefTran_FK
WHERE (((tblTransacciones.fechaTran)>=Nz([Forms]![frmInicio].[Form]![NavigationSubform].[Form]![frmTableroIngresosInicio]![FechaDe],#1/1/2018#) And (tblTransacciones.fechaTran)<=Nz([Forms]![frmInicio].[Form]![NavigationSubform].[Form]![frmTableroIngresosInicio]![FechaA],#12/31/9999#)))
GROUP BY tblTransacciones.tipoTran, tblCuentas.nombreCuenta, tblBeneficiarios.idTpoBenef_FK, tblCuentas.idTipoCuenta_FK
HAVING (((tblTransacciones.tipoTran)="Ingreso") AND ((tblCuentas.idTipoCuenta_FK)<>8));

and this is the SQL query for the TOP 5 results:

SELECT TOP 5 tblTransacciones.tipoTran, Sum(tblTransacciones.montoTran) AS SumOfmontoTran, tblCuentas.nombreCuenta, tblBeneficiarios.idTpoBenef_FK, tblCuentas.idTipoCuenta_FK
FROM tblBeneficiarios INNER JOIN (tblCuentas INNER JOIN tblTransacciones ON tblCuentas.idCuenta = tblTransacciones.cuentaTran_FK) ON tblBeneficiarios.idBeneficiario = tblTransacciones.benefTran_FK
WHERE (((tblTransacciones.fechaTran)>=Nz([Forms]![frmInicio].[Form]![NavigationSubform].[Form]![frmTableroIngresosInicio]![FechaDe],#1/1/2018#) And (tblTransacciones.fechaTran)<=Nz([Forms]![frmInicio].[Form]![NavigationSubform].[Form]![frmTableroIngresosInicio]![FechaA],#12/31/9999#)))
GROUP BY tblTransacciones.tipoTran, tblCuentas.nombreCuenta, tblBeneficiarios.idTpoBenef_FK, tblCuentas.idTipoCuenta_FK
HAVING (((tblTransacciones.tipoTran)="Ingreso") AND ((tblCuentas.idTipoCuenta_FK)<>8))
ORDER BY Sum(tblTransacciones.montoTran) DESC;

Thanks for your support!
 

jdraw

Super Moderator
Staff member
Local time
Today, 17:58
Joined
Jan 23, 2006
Messages
15,379
Using your data and the queries you supplied.

I copied the queries you sent in post as QJ_AllRecords and QJ_Top5.
-Then converted these to Make Table queries (for ease of use) as TJ_AllRecords and TJ_Top5.
-Then used these tables in a query QJ_OtherDetail
Code:
SELECT TJ_AllRecords.tipoTran
, TJ_AllRecords.SumOfmontoTran
, TJ_AllRecords.nombreCuenta
, TJ_AllRecords.idTipoCuenta_FK
, TJ_Top5.nombreCuenta
FROM TJ_AllRecords LEFT JOIN TJ_Top5 ON 
TJ_AllRecords.nombreCuenta = TJ_Top5.nombreCuenta
WHERE (((TJ_Top5.nombreCuenta) Is Null))
ORDER BY TJ_AllRecords.SumOfmontoTran DESC;
to get the "Other records"
-Then this query
Code:
SELECT "Other" AS TmpName
, Sum(QJ_OtherDetail.SumOfmontoTran) AS SumOfSumOfmontoTran
FROM QJ_OtherDetail;
to get a name for this category "Other" and a Total amount

Hope this helps. I have an appointment and must go out for rest of day.
 

Attachments

  • ADS_New.zip
    335.2 KB · Views: 204

evillarrealca

New member
Local time
Today, 16:58
Joined
Mar 23, 2020
Messages
15
Thanks jdraw, I'll see if I can put this together.
I really appreciate your time!
Have a great day!
 

jdraw

Super Moderator
Staff member
Local time
Today, 17:58
Joined
Jan 23, 2006
Messages
15,379
Any status update on this?
 

evillarrealca

New member
Local time
Today, 16:58
Joined
Mar 23, 2020
Messages
15
I tried to put the Querys together but I ended needing 5 querys, I guess it wasn't the way it has to be.
I was also looking a way to import the data from excel.
I appreciate if you can detail a bit more how to do this.
 

poliadisa

New member
Local time
Today, 22:58
Joined
Apr 26, 2020
Messages
7
Hi jdraw, that is correct, the pie will have 6 slices.
I got what you said but how Tutuapp 9Apps ShowBox do I write it into the query? or is it specified in the graph?
for the rest of the Income amount, so I can show a Pie Graph with the Top 5 and "Other" to have the 100% of Income in one Graph. Does any body have done this?
 
Last edited:

evillarrealca

New member
Local time
Today, 16:58
Joined
Mar 23, 2020
Messages
15
Hi jdraw, I just use the routine you sent me, using Is NULL as a Criteria in the query to only select the results I needed (I used this instead of NOT EXISTS) and it worked perfectly. Thank you very much for that input!!
 

mariashare

New member
Local time
Tomorrow, 03:28
Joined
Nov 16, 2021
Messages
1
I think you will need more than 1 query, I haven't done much with charts in quite a while.
 

Users who are viewing this thread

Top Bottom