You can calculate sum of Horizontal and Vertical Column : Using Grid Component

First Create Function To Calculate Sum called : Calculate_Sum

a!localVariables(
  if(
    ri!monthName <> null,
    
      sum(
        todecimal(index(ri!months, { ri!monthName }, 0))
       
    ),
    
      sum(
        todecimal(ri!months.jan, 0),
        todecimal(ri!months.feb, 0),
        todecimal(ri!months.mar, 0),
        todecimal(ri!months.apr, 0),
        todecimal(ri!months.may, 0),
        todecimal(ri!months.june, 0),
        todecimal(ri!months.july, 0),
        todecimal(ri!months.aug, 0),
        todecimal(ri!months.sep, 0),
        todecimal(ri!months.oct, 0),
        todecimal(ri!months.nov, 0),
        todecimal(ri!months.dec, 0)
    
    )
  )
)

Now Create Form in Grid to calculate and call the sum function:

a!localVariables(
local!invalidIncome: ("Please insert valid income value."),
local!DuplicateIncome: (
"Duplicate value. Please check and delete if duplicated"
),
local!CurrentRow: 0,
local!TotalRow: 0,
local!monthDetail: a!map(
jan: null,
feb: null,
mar: null,
apr: null,
may: null,
june: null,
july: null,
aug: null,
sep: null,
oct: null,
nov: null,
dec: null,
total: null
),
local!months: append(
{
local!monthDetail,
local!monthDetail,
local!monthDetail
}
),
local!monthCount: (
if(
sum(index(local!months, "jan", null)) <> 0,
1,
0
) + if(
sum(index(local!months, "feb", null)) <> 0,
1,
0
) + if(
sum(index(local!months, "mar", null)) <> 0,
1,
0
) + if(
sum(index(local!months, "apr", null)) <> 0,
1,
0
) + if(
sum(index(local!months, "may", null)) <> 0,
1,
0
) + if(
sum(index(local!months, "june", null)) <> 0,
1,
0
) + if(
sum(index(local!months, "july", null)) <> 0,
1,
0
) + if(
sum(index(local!months, "aug", null)) <> 0,
1,
0
) + if(
sum(index(local!months, "sep", null)) <> 0,
1,
0
) + if(
sum(index(local!months, "oct", null)) <> 0,
1,
0
) + if(
sum(index(local!months, "nov", null)) <> 0,
1,
0
) + if(
sum(index(local!months, "dec", null)) <> 0,
1,
0
)
),
local!TotalIncome: rule!Calculate_Sum(months: local!months, monthName: null),
local!averageMonthlyIncome: (
if(
and(
local!monthCount > 0,
local!TotalIncome <> 0
),
local!TotalIncome / local!monthCount,
0
)
),
local!averageAnualIncome: (
if(
local!averageMonthlyIncome <> 0,
local!averageMonthlyIncome * 12,
0
)
),
a!formLayout(
label: "Calculator",
contents: {
a!gridLayout(
totalCount: count(local!months),
headerCells: a!forEach(
items: {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sept",
"Oct",
"Nov",
"Dec",
"Total"
},
expression: a!gridLayoutHeaderCell(label: fv!item)
),
rows: a!forEach(
items: local!months,
expression: a!gridRowLayout(
id: fv!index,
contents: {
a!floatingPointField(
label: "January",
value: fv!item.jan,
saveInto: {
fv!item.jan,
a!save(
fv!item.total,
rule!Calculate_Sum(months: fv!item, monthName: null)
),
a!save(local!CurrentRow, fv!index),
a!save(local!TotalRow, length(local!months)),
if(
tointeger(local!CurrentRow) == tointeger(local!TotalRow),
a!save(
local!months,
append(local!months, local!monthDetail)
),
null
)
},
refreshAfter: "KEYPRESS",
validations: {
if(
and(
count(
wherecontains(
todecimal(fv!item.jan),
todecimal(local!months.jan)
)
) > 1,
todecimal(fv!item.jan) > 0
),
local!DuplicateIncome,
null
),
if(
todecimal(fv!item.jan) = 0,
local!invalidIncome,
null
)
}
),
a!floatingPointField(
label: "February",
value: fv!item.feb,
saveInto: {
fv!item.feb,
a!save(
fv!item.total,
rule!Calculate_Sum(months: fv!item, monthName: null)
),
a!save(local!CurrentRow, fv!index),
a!save(local!TotalRow, length(local!months)),
if(
tointeger(local!CurrentRow) == tointeger(local!TotalRow),
a!save(
local!months,
append(local!months, local!monthDetail)
),
null
)
},
refreshAfter: "KEYPRESS",
validations: {
if(
and(
count(
wherecontains(
todecimal(fv!item.feb),
todecimal(local!months.feb)
)
) > 1,
todecimal(fv!item.feb) > 0
),
local!DuplicateIncome,
null
),
if(
todecimal(fv!item.feb) = 0,
local!invalidIncome,
null
)
}
),
a!floatingPointField(
label: "March",
value: fv!item.mar,
saveInto: {
fv!item.mar,
a!save(
fv!item.total,
rule!Calculate_Sum(months: fv!item, monthName: null)
),
a!save(local!CurrentRow, fv!index),
a!save(local!TotalRow, length(local!months)),
if(
tointeger(local!CurrentRow) == tointeger(local!TotalRow),
a!save(
local!months,
append(local!months, local!monthDetail)
),
null
)
},
refreshAfter: "KEYPRESS",
validations: {
if(
and(
count(
wherecontains(
todecimal(fv!item.mar),
todecimal(local!months.mar)
)
) > 1,
todecimal(fv!item.mar) > 0
),
local!DuplicateIncome,
null
),
if(
todecimal(fv!item.mar) = 0,
local!invalidIncome,
null
)
}
),
a!floatingPointField(
label: "April",
value: fv!item.apr,
saveInto: {
fv!item.apr,
a!save(
fv!item.total,
rule!Calculate_Sum(months: fv!item, monthName: null)
),
a!save(local!CurrentRow, fv!index),
a!save(local!TotalRow, length(local!months)),
if(
tointeger(local!CurrentRow) == tointeger(local!TotalRow),
a!save(
local!months,
append(local!months, local!monthDetail)
),
null
)
},
refreshAfter: "KEYPRESS",
validations: {
if(
and(
count(
wherecontains(
todecimal(fv!item.apr),
todecimal(local!months.apr)
)
) > 1,
todecimal(fv!item.apr) > 0
),
local!DuplicateIncome,
null
),
if(
todecimal(fv!item.apr) = 0,
local!invalidIncome,
null
)
}
),
a!floatingPointField(
label: "May",
value: fv!item.may,
saveInto: {
fv!item.may,
a!save(
fv!item.total,
rule!Calculate_Sum(months: fv!item, monthName: null)
),
a!save(local!CurrentRow, fv!index),
a!save(local!TotalRow, length(local!months)),
if(
tointeger(local!CurrentRow) == tointeger(local!TotalRow),
a!save(
local!months,
append(local!months, local!monthDetail)
),
null
)
},
refreshAfter: "KEYPRESS",
validations: {
if(
and(
count(
wherecontains(
todecimal(fv!item.may),
todecimal(local!months.may)
)
) > 1,
todecimal(fv!item.may) > 0
),
local!DuplicateIncome,
null
),
if(
todecimal(fv!item.may) = 0,
local!invalidIncome,
null
)
}
),
a!floatingPointField(
label: "June",
value: fv!item.june,
saveInto: {
fv!item.june,
a!save(
fv!item.total,
rule!Calculate_Sum(months: fv!item, monthName: null)
),
a!save(local!CurrentRow, fv!index),
a!save(local!TotalRow, length(local!months)),
if(
tointeger(local!CurrentRow) == tointeger(local!TotalRow),
a!save(
local!months,
append(local!months, local!monthDetail)
),
null
)
},
refreshAfter: "KEYPRESS",
validations: {
if(
and(
count(
wherecontains(
todecimal(fv!item.june),
todecimal(local!months.june)
)
) > 1,
todecimal(fv!item.june) > 0
),
local!DuplicateIncome,
null
),
if(
todecimal(fv!item.june) = 0,
local!invalidIncome,
null
)
}
),
a!floatingPointField(
label: "July",
value: fv!item.july,
saveInto: {
fv!item.july,
a!save(
fv!item.total,
rule!Calculate_Sum(months: fv!item, monthName: null)
),
a!save(local!CurrentRow, fv!index),
a!save(local!TotalRow, length(local!months)),
if(
tointeger(local!CurrentRow) == tointeger(local!TotalRow),
a!save(
local!months,
append(local!months, local!monthDetail)
),
null
)
},
refreshAfter: "KEYPRESS",
validations: {
if(
and(
count(
wherecontains(
todecimal(fv!item.july),
todecimal(local!months.july)
)
) > 1,
todecimal(fv!item.july) > 0
),
local!DuplicateIncome,
null
),
if(
todecimal(fv!item.july) = 0,
local!invalidIncome,
null
)
}
),
a!floatingPointField(
label: "August",
value: fv!item.aug,
saveInto: {
fv!item.aug,
a!save(
fv!item.total,
rule!Calculate_Sum(months: fv!item, monthName: null)
),
a!save(local!CurrentRow, fv!index),
a!save(local!TotalRow, length(local!months)),
if(
tointeger(local!CurrentRow) == tointeger(local!TotalRow),
a!save(
local!months,
append(local!months, local!monthDetail)
),
null
)
},
refreshAfter: "KEYPRESS",
validations: {
if(
and(
count(
wherecontains(
todecimal(fv!item.aug),
todecimal(local!months.aug)
)
) > 1,
todecimal(fv!item.aug) > 0
),
local!DuplicateIncome,
null
),
if(
todecimal(fv!item.aug) = 0,
local!invalidIncome,
null
)
}
),
a!floatingPointField(
label: "September",
value: fv!item.sep,
saveInto: {
fv!item.sep,
a!save(
fv!item.total,
rule!Calculate_Sum(months: fv!item, monthName: null)
),
a!save(local!CurrentRow, fv!index),
a!save(local!TotalRow, length(local!months)),
if(
tointeger(local!CurrentRow) == tointeger(local!TotalRow),
a!save(
local!months,
append(local!months, local!monthDetail)
),
null
)
},
refreshAfter: "KEYPRESS",
validations: {
if(
and(
count(
wherecontains(
todecimal(fv!item.sep),
todecimal(local!months.sep)
)
) > 1,
todecimal(fv!item.sep) > 0
),
local!DuplicateIncome,
null
),
if(
todecimal(fv!item.sep) = 0,
local!invalidIncome,
null
)
}
),
a!floatingPointField(
label: "October",
value: fv!item.oct,
saveInto: {
fv!item.oct,
a!save(
fv!item.total,
rule!Calculate_Sum(months: fv!item, monthName: null)
),
a!save(local!CurrentRow, fv!index),
a!save(local!TotalRow, length(local!months)),
if(
tointeger(local!CurrentRow) == tointeger(local!TotalRow),
a!save(
local!months,
append(local!months, local!monthDetail)
),
null
)
},
refreshAfter: "KEYPRESS",
validations: {
if(
and(
count(
wherecontains(
todecimal(fv!item.oct),
todecimal(local!months.oct)
)
) > 1,
todecimal(fv!item.oct) > 0
),
local!DuplicateIncome,
null
),
if(
todecimal(fv!item.oct) = 0,
local!invalidIncome,
null
)
}
),
a!floatingPointField(
label: "November",
value: fv!item.nov,
saveInto: {
fv!item.nov,
a!save(
fv!item.total,
rule!Calculate_Sum(months: fv!item, monthName: null)
),
a!save(local!CurrentRow, fv!index),
a!save(local!TotalRow, length(local!months)),
if(
tointeger(local!CurrentRow) == tointeger(local!TotalRow),
a!save(
local!months,
append(local!months, local!monthDetail)
),
null
)
},
refreshAfter: "KEYPRESS",
validations: {
if(
and(
count(
wherecontains(
todecimal(fv!item.nov),
todecimal(local!months.nov)
)
) > 1,
todecimal(fv!item.nov) > 0
),
local!DuplicateIncome,
null
),
if(
todecimal(fv!item.nov) = 0,
local!invalidIncome,
null
)
}
),
a!floatingPointField(
label: "December",
value: fv!item.dec,
saveInto: {
fv!item.dec,
a!save(
fv!item.total,
rule!Calculate_Sum(months: fv!item, monthName: null)
),
a!save(local!CurrentRow, fv!index),
a!save(local!TotalRow, length(local!months)),
if(
tointeger(local!CurrentRow) == tointeger(local!TotalRow),
a!save(
local!months,
append(local!months, local!monthDetail)
),
null
)
},
refreshAfter: "KEYPRESS",
validations: {
if(
and(
count(
wherecontains(
todecimal(fv!item.dec),
todecimal(local!months.dec)
)
) > 1,
todecimal(fv!item.dec) > 0
),
local!DuplicateIncome,
null
),
if(
todecimal(fv!item.dec) = 0,
local!invalidIncome,
null
)
}
),
a!richTextDisplayField(
value: {
a!richTextItem(
style: "STRONG",
text: pound(rule!Calculate_Sum(months: fv!item, monthName: null))
)
}
)
}
)
),
/*addRowlink: a!dynamicLink(
label: "Add",
saveInto: {
a!save(
local!months,
append(local!months, save!value)
)
}
),*/
rowHeader: 1
),
a!columnsLayout(
columns: {
a!columnLayout(
contents: {
a!richTextDisplayField(
value: {
a!richTextItem(
style: "STRONG",
text: pound(rule!Calculate_Sum(months: local!months, monthName: "jan"))
)
},

)
}
),
a!columnLayout(
contents: {
a!richTextDisplayField(
value: {
a!richTextItem(
style: "STRONG",
text: pound(rule!Calculate_Sum(months: local!months, monthName: "feb"))
)
}
)
}
),
a!columnLayout(
contents: {
a!richTextDisplayField(
value: {
a!richTextItem(
style: "STRONG",
text: pound(rule!Calculate_Sum(months: local!months, monthName: "mar"))
)
}
)
}
),
a!columnLayout(
contents: {
a!richTextDisplayField(
value: {
a!richTextItem(
style: "STRONG",
text: pound(rule!Calculate_Sum(months: local!months, monthName: "apr"))
)
}
)
}
),
a!columnLayout(
contents: {
a!richTextDisplayField(
value: {
a!richTextItem(
style: "STRONG",
text: pound(rule!Calculate_Sum(months: local!months, monthName: "may"))
)
}
)
}
),
a!columnLayout(
contents: {
a!richTextDisplayField(
value: {
a!richTextItem(
style: "STRONG",
text: pound(rule!Calculate_Sum(months: local!months, monthName: "june"))
)
}
)
}
),
a!columnLayout(
contents: {
a!richTextDisplayField(
value: {
a!richTextItem(
style: "STRONG",
text: pound(rule!Calculate_Sum(months: local!months, monthName: "july"))
)
}
)
}
),
a!columnLayout(
contents: {
a!richTextDisplayField(
value: {
a!richTextItem(
style: "STRONG",
text: pound(rule!Calculate_Sum(months: local!months, monthName: "aug"))
)
}
)
}
),
a!columnLayout(
contents: {
a!richTextDisplayField(
value: {
a!richTextItem(
style: "STRONG",
text: pound(rule!Calculate_Sum(months: local!months, monthName: "sep"))
)
}
)
}
),
a!columnLayout(
contents: {
a!richTextDisplayField(
value: {
a!richTextItem(
style: "STRONG",
text: pound(rule!Calculate_Sum(months: local!months, monthName: "oct"))
)
}
)
}
),
a!columnLayout(
contents: {
a!richTextDisplayField(
value: {
a!richTextItem(
style: "STRONG",
text: pound(rule!Calculate_Sum(months: local!months, monthName: "nov"))
)
}
)
}
),
a!columnLayout(
contents: {
a!richTextDisplayField(
value: {
a!richTextItem(
style: "STRONG",
text: pound(rule!Calculate_Sum(months: local!months, monthName: "dec"))
)
}
)
}
),
a!columnLayout(
contents: {
a!richTextDisplayField(
value: {
a!richTextItem(style: "STRONG", text: pound(local!TotalIncome))
}
)
}
)
}
),
a!sectionLayout(
label: null,
contents: {
a!columnsLayout(
columns: {
a!columnLayout(
contents: {
a!cardLayout(
contents: {
a!richTextDisplayField(
labelPosition: "ABOVE",
value: {
a!richTextItem(
text: "Average Monthly Income",
size: "MEDIUM_PLUS",
style: "STRONG"
)
},
align: "CENTER"
),
a!richTextDisplayField(
labelPosition: "ABOVE",
value: {
a!richTextItem(
style: "STRONG",
text: pound(local!averageMonthlyIncome)
)
},
align: "CENTER"
)
},
shape: "SQUARED",
showBorder: true,
showShadow: false,
padding: "LESS",
height: "AUTO",
style: "NONE",
decorativeBarPosition: "NONE"
)
}
),
a!columnLayout(
contents: {
a!cardLayout(
contents: {
a!richTextDisplayField(
labelPosition: "ABOVE",
value: {
a!richTextItem(
style: "STRONG",
text: "Average Annual Income",
size: "MEDIUM_PLUS"
)
},
align: "CENTER"
),
a!richTextDisplayField(
labelPosition: "ABOVE",
value: {
a!richTextItem(
style: "STRONG",
text: pound(local!averageAnualIncome)
)
},
align: "CENTER"
)
},
shape: "SQUARED",
showBorder: true,
showShadow: false,
padding: "LESS",
height: "AUTO",
style: "NONE",
decorativeBarPosition: "NONE"
),

}
),
a!columnLayout(
contents: {
a!cardLayout(
contents: {
a!richTextDisplayField(
labelPosition: "ABOVE",
value: {
a!richTextItem(
text: "Total Income",
size: "MEDIUM_PLUS",
style: "STRONG"
)
},
align: "CENTER"
),
a!richTextDisplayField(
labelPosition: "ABOVE",
value: {
a!richTextItem(style: "STRONG", text: pound(local!TotalIncome))
},
align: "CENTER"
)
},
shape: "SQUARED",
showBorder: true,
showShadow: false,
padding: "LESS",
height: "AUTO",
style: "NONE",
decorativeBarPosition: "NONE"
)
}
)
}
)
}
)
}
)
)

  Discussion posts and replies are publicly visible

Parents
  • Please make your question more readable. 

    • This is just calculator I develop for my reference use. How can we post our thread for help people to use in future to develop similar task.
  • 0
    Appian Employee
    in reply to ahirajay15

    It's helpful to share a sample expression like this, but I'd strongly recommend editing your post and providing the explanation for what it is within your post. Otherwise other folks that search / view this post won't understand what this is or why you have shared it.

  • 0
    Certified Lead Developer
    in reply to ahirajay15

    In addition to what Peter suggested, when you edit your post please add a "Code Box" (as demonstrated in Harshit's comment already) and re-paste your code into that (i suggest you re-copy it from the original source so that it maintains indentation).  Such long, unindented code in the plaintext font used by default for posts here is, quite frankly, unreadable and reads the original post nearly impossible to parse at all.

    Additionally we're perfectly happy to look at / consider / heap praises upon new/unique components/tools/utilities here, though if you're trying to show off something you've made (which i welcome), it would also be neat to see a screenshot of what the finished product does, accompanying the code.  Otherwise all we really see is a mass of code (and in this case, about 19 pages of it since it's not in a code box).

    Side note: the above-pasted code isn't really useful to copy/paste (even for preview purposes) as it uses "rule!PIB_BankStatement_Sum()" 26 times, and I don't even really have a guess as to what this function would do.  But without it in the recipient environment, it just displays an error message.

Reply
  • 0
    Certified Lead Developer
    in reply to ahirajay15

    In addition to what Peter suggested, when you edit your post please add a "Code Box" (as demonstrated in Harshit's comment already) and re-paste your code into that (i suggest you re-copy it from the original source so that it maintains indentation).  Such long, unindented code in the plaintext font used by default for posts here is, quite frankly, unreadable and reads the original post nearly impossible to parse at all.

    Additionally we're perfectly happy to look at / consider / heap praises upon new/unique components/tools/utilities here, though if you're trying to show off something you've made (which i welcome), it would also be neat to see a screenshot of what the finished product does, accompanying the code.  Otherwise all we really see is a mass of code (and in this case, about 19 pages of it since it's not in a code box).

    Side note: the above-pasted code isn't really useful to copy/paste (even for preview purposes) as it uses "rule!PIB_BankStatement_Sum()" 26 times, and I don't even really have a guess as to what this function would do.  But without it in the recipient environment, it just displays an error message.

Children