How to Show Total, avg etc at bottom of Column in script report?

Hello @community,

I have developed script reports in my custom app. Now i want to show total and avg of value fetched on based on filter in script report. How can i show this in last.

Thanks,
Hardik Gadesha

Check the Add Total Row in your script report.

see this.

@Sangram

I already Did this, that’s why it shown in my script report. But how to get value there ? That’s my query.

Total is only shown for "Currency", "Int", "Float", "Percent", "Data" fieldtype.
Please check your field types of columns in script report.

1 Like

Thanks @Sangram for your reply.

Yeah, it’s working now. i tried Data field type but did not work for that, It’s working for Int. But how can i show avg as like sum in bottom. I want to show Avg of column for other reports.

1 Like

@Hardik_Gadesha

Add Total Row is by default functionality of framework for the report.
Please check this,

you can write your script for Average Row

Yes, I will write it but how to show this in bottom ?

Append it to final data of report. Go through query_report.py. Check how they add Total Row.

Okay.

Thanks A lot @Sangram :slight_smile:

Hello,

How can i find avg of column and show it to bottom of the report ?

@Hardik_Gadesha

Have you tried anything?
Please share your script. So, I can help you better.

Here is my python script. @Sangram

`from future import unicode_literals
import frappe
from frappe import _

def execute(filters=None):
columns = get_column()
data = get_data(filters)
return columns,data

def get_column():
return [(“Ballmill No”) + “:Data:100”,(“Ballmill Date”) + “:date:100”,(“Kanta No”) + “:Data:100”, (“By Whom”) + “::100”,(“Time”) + “::100”, (“Dencity”)+“:Float:100”, (“Viscocity”) + “:Float:100”,(“Residue”) + “:Float:100”,(“Grinding”) + “::100”,(“Remarks”) + “::180”]

def get_data(filters):
if filters.get(“from_date”,“to_date”):
from_date = filters.get(“from_date”)
to_date = filters.get(“to_date”)
ballmill_DVRG = frappe.db.sql(“”"
select obj1.ballmill_name, obj1.date, obj1.weigh_bridge, obj2.by_whom,obj2.time,obj2.density, obj2.viscosity, obj2.residue, obj2.grinding,obj2.remarks from tabBallmill obj1, tabCT1 obj2 where (obj1.weigh_bridge = obj2.parent) and (obj1.date between ‘%s’ and ‘%s’) ORDER BY obj1.date ASC,obj2.idx ASC;“”" %(from_date,to_date), as_list=1)

    return ballmill_DVRG`

I want avg of density, viscosity, residue at bottom of it’s particular column.

Thanks,
Hardik Gadesha

ballmill_DVRG this is your result.

add your logic here. Calculate the average of columns you want. Then add calculated Average Column to it and return the result.

Check query_report.py

Thanks,
Sangram

Okay @Sangram.

I will try this :slight_smile:

Thanks for your kind reply.