Request help with complex calculations

Hello All,

I am stuck in figuring out complex calculations involving multiple conditions. I request your help in finding the right direction & logic for solving it.
As seen in the below image, I have a table listing the areas & nos of different rooms. The Available Nos is entered by the user while filling the form. I am stuck at calculating the Required Nos for the corresponding rooms.

The conditions for arriving at Required Nos for each room differ from one another. For example, No. of Class Room = (No. of Divisions * Course Duration). No. of Tutorial Room = (No. of Classroom / 4) the fraction should be rounded to next integer.
No. of Laboratory = 10 per Course.

I request your help in understanding which components can be used for calculating these values and how to fill the dynamic table with these values for comparison.

Hey AJ,

  1. Personally I can't find in your table the variables needed for the calculations...
  2. Are those variables coming from the same query?

Can you please explain better/more?

Yes, the variables are coming from the same query. It is a nested query, and the course duration & no. of divisions are part of the main table & the room details are part of the sub-table

This is how I have displayed the table

Hope this is helpful in some ways to understand the issue.

OK , I see.

Can you please share your query output in order to fully understand and give you an answer that is built using your specific field query field names?

This is the output. I have shown output for only single course, there are other courses as well.

{
repeat_UGCourses: [
{},
{
courseName: "Mechanical Engineering",
courseID: 3,
courseDuration: 4,
divCount: 1,
isNewCourse: "E",
sanctDivSum: 1,
propDivSum: null,
yearCount: 1,
query_instructionalAreaUGCourses: [
{
roomName: "Class Room",
roomID: 1,
roomArea: 136,
roomCount: 2,
masterRoomReq: [
{
roomName: "Class Room",
reqRoomArea: 66
}
]
},
{
roomName: "Tutorial Room",
roomID: 2,
roomArea: 1045,
roomCount: 2,
masterRoomReq: [
{
roomName: "Tutorial Room",
reqRoomArea: 33
}
]
},
{
roomName: "Drawing Hall",
roomID: 4,
roomArea: 100,
roomCount: 1,
masterRoomReq: [
{
roomName: "Drawing Hall",
reqRoomArea: 132
}
]
},
{
roomName: "Seminar Hall",
roomID: 6,
roomArea: 2000,
roomCount: 1,
masterRoomReq: [
{
roomName: "Seminar Hall",
reqRoomArea: 132
}
]
},
{
roomName: "Additional Lab/Workshop  for category X courses",
roomID: 213,
roomArea: 85,
roomCount: 1,
masterRoomReq: [
{
roomName: "Additional Lab/Workshop  for category X courses",
reqRoomArea: 200
}
]
}
]
},

Sorry but it just happened to have a service visit for my internet line upgrade to fiber optics...

From what I understood these are the calculations:
No. of Class Room = (No. of Divisions * Course Duration).
No. of Class Room = divCount * courseDuration

No. of Tutorial Room = (No. of Classroom / 4) the fraction should be rounded to next integer.
No. of Tutorial Room = (query_instructionalAreaUGCourses.count() / 4).ceil()
**I'm not sure if (No. of Classroom) is correctly pointed to query_instructionalAreaUGCourses.count()

No. of Laboratory = 10 per Course.
No. of Laboratory = 10 * query_instructionalAreaUGCourses.count()

If you don't get the right calculations let us know... Maybe I understood wrong a variable

I want to understand, when I use those calculations how to display the values against the room name row in the table?

show us the code for this table

Here is the code for that table:

<div class="row">
                                <div class="col" is="dmx-repeat" id="repeat3" dmx-bind:repeat="sc_qry_instbackground.data.repeat_UGCourses_copy">
                                    <p><b>Instructional Area (Carpet Area in sq. m)&nbsp; UG Course Room Count Calculation</b></p>
                                    <p><b>Course Name: {{courseName}}</b></p>
                                    <p><b>Course Division: {{sanctDivSum+propDivSum}}</b></p>
                                    <p><b>Course Duration: {{courseDuration}}</b></p>
                                    <div class="table-responsive small text-center" dmx-hide="sc_qry_instbackground.data.query_continuationCoursesUG[0].courseName.isEmpty()">
                                        <table class="table align-middle table-bordered table-hover table-sm text-center border-dark">
                                            <thead class="align-middle text-center small">
                                                <tr>
                                                    <th>Course Name</th>
                                                    <th>Room Name</th>
                                                    <th>Required Nos</th>
                                                    <th>Available Nos</th>
                                                    <th>Required Area</th>
                                                    <th>Available Area</th>
                                                    <th>Remarks</th>
                                                    <th>Proposed Intake</th>
                                                </tr>
                                            </thead>
                                            <tbody is="dmx-repeat" dmx-generator="bs5table" id="tableRepeat10" class="align-middle small" dmx-bind:repeat="query_instructionalAreaUGCourses_copy">
                                                <tr>
                                                    <td dmx-text="courseName"></td>
                                                    <td dmx-text="roomName"></td>
                                                    <td dmx-text="(roomID == 1)?noDivs:(roomID == 2)?noDiv/4:NA"></td>
                                                    <td dmx-text="roomCount" class="text-center"></td>
                                                    <td dmx-text="(masterRoomReq[0].reqRoomArea * roomCount)" class="text-center"></td>
                                                    <td dmx-text="roomArea" class="text-center"></td>
                                                    <td class="text-center" dmx-text="(roomArea &gt;= masterRoomReq[0].reqRoomArea)?'No Deficiency':'Deficiency'"></td>
                                                    <td class="text-center"></td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>

ok.. now I got what you need

Give me a few minutes

I'm not sure about one thing:
No. of Tutorial Room = (No. of Classroom / 4) the fraction should be rounded to next integer.
**(No. of Classroom) is correctly query_instructionalAreaUGCourses.count() ?

Anyway, can you check if the results on this table are correct?

I replaced only the "Required Nos" dmx-text values

<!-- OLD
<td dmx-text="(roomID == 1)?noDivs:(roomID == 2)?noDiv/4:NA"></td> -->

<!-- NEW -->                            
<td dmx-text="(roomID == 1)?(divCount * courseDuration):(roomID == 2)?((query_instructionalAreaUGCourses.count() / 4).ceil()):''"></td>
1 Like

Thanks for your help.
I will check and let you know if it works.

Hey Many Thanks @famousmag the solution is working perfectly.

I have few other conditions to be applied for other rooms, is this the best way to continue using Ternary Operator or there might be some other easy solution to the problem.

I just want to understand, what would you, being an expert, do in such a scenario?

Hey AJ,

Glad it worked for you.
*I'm not an expert... Just trying buddy

Ternary operator would be fine i suppose for this kind of "one shot" inline conditional results.
In other cases you would like to filter your whole repeat procedure, you could use the formatters like .where() , .filter() etc, directly on your datasourse/expression

We all are trying & learning, but because of helpful members like you, beginners like myself progress daily!!

.where() & .filer()... those are new terms for me. If you have any links related to these topics can you share for further reading.

Anyways, i will stick with Ternary Operator till it gets the job done!

Thanks once again.