Sum the GL account balance filtered by dimensions

Hi All,

I need to add a field on Purchase Invoice Line such when I select a GL type option followed by G/L account on the line, the additional field should be populated by the sum / balance of the GL account filtered by dimension(s).

Am using the code below in my new field

FieldClass = FlowField;
AutoFormatType = 1;
CalcFormula = Sum ("G/L Entry".Amount WHERE("G/L Account No." = FIELD("No.")));
// "G/L Account No." = FIELD(FILTER(Totaling)),
//"Business Unit Code" = FIELD("Business Unit Filter"),
//"Global Dimension 1 Code" = FIELD("Global Dimension 1 Filter"),
//"Global Dimension 2 Code" = FIELD("Global Dimension 2 Filter"),
//"Dimension Set ID" = FIELD("Dimension Set ID Filter")));

but am getting errors on the commented lines, is there something wrong or is there a better way to get the balance of the selected GL entry?.