diff --git a/frappe/public/js/frappe/ui/group_by/group_by.html b/frappe/public/js/frappe/ui/group_by/group_by.html
index a631dc5266..ea7b75233b 100644
--- a/frappe/public/js/frappe/ui/group_by/group_by.html
+++ b/frappe/public/js/frappe/ui/group_by/group_by.html
@@ -10,11 +10,14 @@
{% for (var parent_doctype in group_by_conditions) { %}
{% for (var val of group_by_conditions[parent_doctype]) { %}
+ {% field_name = val.label || val.fieldname %}
+ {% if(val.parent && doctype != val.parent) field_name += " ("+parent_doctype+")" %}
{% } %}
{% } %}
diff --git a/frappe/public/js/frappe/ui/group_by/group_by.js b/frappe/public/js/frappe/ui/group_by/group_by.js
index f13c865834..6bb83334f3 100644
--- a/frappe/public/js/frappe/ui/group_by/group_by.js
+++ b/frappe/public/js/frappe/ui/group_by/group_by.js
@@ -243,6 +243,11 @@ frappe.ui.GroupBy = class {
}
apply_group_by() {
+ if (this.group_by_doctype != this.aggregate_on_doctype) {
+ frappe.msgprint("Parent-to-child or child-to-parent grouping is not allowed.");
+ return false;
+ }
+
this.group_by = "`tab" + this.group_by_doctype + "`.`" + this.group_by_field + "`";
if (this.aggregate_function === "count") {