---
id: post/sauravdhyani-com/tag-blogger-com-1999-blog-3122193036149030463-post-7756402263170151476--0af9b880b1
type: post
title: How to Group and Consolidate General Journal Lines Using Query Object in Business Central.
summary: This post explains how to consolidate General Journal Lines in Business Central using Query Objects to group records by Posting Date, Account No., and Dimension Set ID, then aggregate amounts and insert consolidated results into a target journal batch. It addresses a common developer scenario where multiple journal lines with identical keys need to be combined.
tier: community
language: en
tags:
  - query object
  - general journal
  - consolidation
  - grouping
  - aggregation
  - al development
  - performance
system: finance
review:
  state: reviewed
  by: opus
  at: "2026-10-08T01:55:43.026Z"
  flags: []
generated:
  at: "2026-10-08T01:26:53.141Z"
  pipeline: 0.2.0
  prompts:
    extract-post: 1
  input_hash: 7c7a94404dcd372be45228ab641b2a497538d5e3cc02e13a3b9d2f21fc10741a
evidence:
  - kind: blog
    url: https://www.sauravdhyani.com/2026/04/how-to-group-and-consolidate-general.html
    title: How to Group and Consolidate General Journal Lines Using Query Object in Business Central.
    date: "2026-04-01"
    commit: null
    t: null
    quote: null
  - kind: blog
    url: https://www.sauravdhyani.com/2026/04/how-to-group-and-consolidate-general.html
    title: How to Group and Consolidate General Journal Lines Using Query Object in Business Central.
    date: "2026-04-01"
    commit: null
    t: null
    quote: Query Objects are read-only. You cannot insert or modify records directly from a Query Object.
  - kind: blog
    url: https://www.sauravdhyani.com/2026/04/how-to-group-and-consolidate-general.html
    title: How to Group and Consolidate General Journal Lines Using Query Object in Business Central.
    date: "2026-04-01"
    commit: null
    t: null
    quote: For grouping and aggregation scenarios, Query Object is the correct architectural choice.
links:
  learn: []
  objects:
    - object/table/81
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
post_id: tag:blogger.com,1999:blog-3122193036149030463.post-7756402263170151476
source_id: sauravdhyani-com
source_name: Saurav Dhyani
url: https://www.sauravdhyani.com/2026/04/how-to-group-and-consolidate-general.html
published_at: "2026-04-01T04:30:00.032Z"
author: Saurav Dhyani
full_text: false
words: 715
quotes:
  - text: Query Objects are read-only. You cannot insert or modify records directly from a Query Object.
    why_it_matters: Critical clarification of a common misconception that guides developers toward the correct architectural pattern
  - text: For grouping and aggregation scenarios, Query Object is the correct architectural choice.
    why_it_matters: Direct statement of the post's main recommendation about best practices for consolidation scenarios
code_objects_mentioned:
  - table Gen. Journal Line
systems:
  - finance
  - development
versions_mentioned: []
preview:
  embeddable: true
  frame_url: null
  image: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0zbJwBx2itOC0mDpqHlTTLnI1s31yhSpYjHTPTFti9a4rzBYl5JQtTUU14Qu3pBjm7Uoc6jPtfc1eRnypU40lWyz8PwbRIhB5iryxE3GQHlUy82gFWFR1Os84WRmuPXtQMNAPvKLeWNJ4c3k4pWNIIx42UaJvFa2eZWYgMwHP5OYkYveT2m17S8CiMjA/w1200-h630-p-k-no-nu/ChatGPT%20Image%20Jan%205,%202026,%2001_01_16%20PM.png
  image_alt: null
  image_w: null
  image_h: null
  site_name: null
  favicon: https://www.sauravdhyani.com/favicon.ico
  probed_at: "2026-10-07T11:50:39.243Z"
---

# How to Group and Consolidate General Journal Lines Using Query Object in Business Central.

[Read the post](https://www.sauravdhyani.com/2026/04/how-to-group-and-consolidate-general.html) · Saurav Dhyani (Saurav Dhyani, MVP) · 2026-04-01 · 715 words · tier community · reviewed (checked by Opus)

> This post explains how to consolidate General Journal Lines in Business Central using Query Objects to group records by Posting Date, Account No., and Dimension Set ID, then aggregate amounts and insert consolidated results into a target journal batch. It addresses a common developer scenario where multiple journal lines with identical keys need to be combined.

## Key points

- Query Objects are the correct tool for consolidation because they handle grouping and SUM aggregation efficiently, unlike manual record looping
- Consolidation keys typically include Posting Date, Account No., and Dimension Set ID, with Amount field aggregated using SUM
- Query Objects are read-only; the pattern requires executing the query, looping results, creating new journal lines in target batch, then deleting source lines
- Manual record looping approaches are complex, error-prone, and perform poorly compared to Query Objects for grouping scenarios
- Safe consolidation requires keeping source batch untouched until target insertion completes successfully to prevent data loss

## Quotes

- "Query Objects are read-only. You cannot insert or modify records directly from a Query Object." (Critical clarification of a common misconception that guides developers toward the correct architectural pattern)
- "For grouping and aggregation scenarios, Query Object is the correct architectural choice." (Direct statement of the post's main recommendation about best practices for consolidation scenarios)

## AL objects mentioned

As named in the post. A name that matches one object page by exact type and name links to it; the others stay as named.

- [table 81 "Gen. Journal Line"](../../objects/table/81.md)

## Context

- Features: General Journal consolidation, Query-based grouping, Record aggregation with SUM, Batch processing, Safe data transfer between batches, AL code patterns for consolidation

Source: Saurav Dhyani, community blog. Summary, key points and quotes are derived (CONTENT-NOTICE.md); read the original for the full text.
