web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Error in this formula ...
Power Apps
Unanswered

Error in this formula using ClearCollect

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello,

I have a ClearCollect and a Collect function which gives the following error and I cannot see what I've done wrong.

 

Error: "There is an error in this formula: Try revising the formula and running it again"

 

I'll list the code here shortly. If I comment out the ClearCollect and Collect functions, all other formulas work and give correct results, but the moment I add the ClearCollect or Collect functions then the error appears.

 

Can anyone please help with what I might be doing wrong?

 

Thanks

Ian

 

Code in my app

In one button the Code is: -

Set(varTrajNo, 1);
Set(blChuteCalc, false);
Set(vRho, constSLRHO*(0.9)^(recRocket.Elev/1000));
Set(vSFC, recRocket.RocketArea);
Set(vCF, recRocket.RocketDrag);
Switch(varTrajNo,
1,
Set(vAng,vLAngle),
2,
Set(vAng,vLAngle),
3,
Set(vAng,vFailAngle)
);
Set(vMas, recRocket.MassTotal);
Set(vForceY, ((0-recRocket.MassTotal)*constGravity));
Set(vForce, Abs(vForceY));
Set(vAccelY, (((0-recRocket.MassTotal)*constGravity)/recRocket.MassTotal));
Set(vAccel, vAccelY);
Set(vVelY, (vForceY/recRocket.MassTotal*recRocket.TimeDelta));
Set(vVel, vVelY);
Set(vWindSFC, recRocket.SFCWind);

ClearCollect(clTraj,
{
zLineNo: 0,
zTimeCounter: 0,
zRho: vRho,
zSFCarea: vSFC,
zAngle: vAng,
zCOEFF: vCF,
zDragX: 0,
zDragY: 0,
zDrag: 0,
zThrust: 0,
zThrustX: 0,
zThrustY: 0,
zPathX: 0,
zPathY: 0,
zPath: 0,
zGravityX: 0,
zGravityY: constGravity,
zTotalMass: vMas,
zForceX: 0,
zForceY: vForceY,
zForce: vForce,
zAccelX: 0,
zAccelY: vAccelY,
zAccel: vAccel,
zVelocityX: 0,
zVelocityY: vVelY,
zVelocity: vVel,
zWind: vWindSFC,
zWindX: 0,
zDist: 0,
zChuteOpen: 100000,
zApogeeReached: false,
zApogee: 0,
zApogeeTime: 100000,
zStage: 1,
zFinished: false
}
)

 

 

The second button, the code is

Set(recLast,Last(clTraj));
Set(xLineNo,recLast.zLineNo+1);
If(!blChuteCalc,
Switch(recRocket.ChuteMethod,
"ALT",
If(And(recLast.zApogeeReached,((recLast.zPathY+recRocket.Elev)<recRocket.ChuteOpenData)),
Set(vParaOpen,recLast.zTimeCounter-(2*vTimeDelta));
Set(blChuteCalc, true ),
Set(vParaOpen,100000)
),
"BURN",
Set(vParaOpen,
Max(recRocket.M1Burn+recRocket.ChuteOpenData,recRocket.M1Burn+recRocket.M2Delay+recRocket.M2Burn+recRocket.ChuteOpenData,
recRocket.M1Burn+recRocket.M2Delay+recRocket.M2Burn+recRocket.M3Delay+recRocket.M3Burn+recRocket.ChuteOpenData)
);
Set(blChuteCalc, true)
,
"APO",
If(recLast.zApogeeReached,
Set(vParaOpen,recLast.zApogeeTime+recRocket.ChuteOpenData);
Set(blChuteCalc, true ),
Set(vParaOpen,100000)
)
)
);
Set(vCounter,recLast.zTimeCounter+vTimeDelta);
Set(vRho,constSLRHO*(0.9)^((recLast.zPathY+recRocket.Elev)/1000));
Set(vWind,recRocket.SFCWind*(((recLast.zPathY+recRocket.Elev)/recRocket.Elev)^constWindShear);
If(recLast.zTimeCounter<recLast.zChuteOpen,
Set(vSFC,recRocket.RocketArea);
Set(vCF,recRocket.RocketDrag),
Set(vSFC,recRocket.ChuteArea);
Set(vCF,recRocket.ChuteDrag)
);
If(recLast.zVelocityY=Abs(recLast.zVelocityY),
Set(dSign,1),
Set(dSign,-1)
);
Set(vdg,vCF*0.5*vRho*vSFC*recLast.zVelocityY^2*dSign);
If(vCounter<(recRocket.M1Burn+recRocket.M2Delay),
Set(vstage,1),
If(vCounter<(recRocket.M1Burn+recRocket.M2Delay+recRocket.M2Burn+recRocket.M3Delay),
Set(vstage,2),
Set(vstage,3)
)
);
Switch(vstage,
1,
If(vCounter<recRocket.M1Burn,
Set(vMas,((recLast.zTotalMass) - (recRocket.M1Reduce)));
Set(vTH,recRocket.M1Thrust),
If(vCounter<recRocket.M1Eject,
Set(vMas,recLast.zTotalMass);
Set(vTH,0),
Set(vMas,(recLast.zTotalMass - recRocket.M1EngMass));
Set(vTH,0)
)
),
2,
If(vCounter<recRocket.M2Burn,
Set(vMas,(recLast.zTotalMass-recRocket.M2Reduce));
Set(vTH,recRocket.M2Thrust),
If(vCounter<recRocket.M2Eject,
Set(vMas,recLast.zTotalMass);
Set(vMas,(recLast.zTotalMass-recRocket.M2EngMass));
Set(vTH,0)
)
),
3,
If(vCounter<recRocket.M3Burn,
Set(vMas,(recLast.zTotalMass-recRocket.M3Reduce));
Set(vTH,recRocket.M3Thrust),
Set(vMas,recLast.zTotalMass);
Set(vTH,0)
)
);
If(recLast.zPath<recRocket.Rod,
Set(vGX,constGravity*Cos(recLast.zAngle)*Sin(recLast.zAngle));
Set(vGY,constGravity*(Cos(recLast.zAngle))^2),
Set(vGX,0);
Set(vGY,constGravity)
);
Set(vDragX,vdg*Sin(recLast.zAngle));
Set(vDragY,vdg*Cos(recLast.zAngle));
Set(vThrX,vTH*Sin(recLast.zAngle));
Set(vThrY,vTH*Cos(recLast.zAngle));
Set(vForceX,(vThrX-vDragX-(vMas*vGX)));
Set(vForceY,(vThrY-vDragY-(vMas*vGY)));
Set(vForce,Sqrt(vForceX^2+vForce^2));
Set(vAccelX,vForceX/vMas);
Set(vAccelY,vForceY/vMas);
Set(vVelX,recLast.zVelocityX+(vForceX/vMas)*vTimeDelta);
Set(vVelY,recLast.zVelocityY+(vForceY/vMas)*vTimeDelta);
Set(vVel,Sqrt(vVelX^2+vVelY^2));
Set(vWindX,
If(vGY<>constGravity,
0,
recLast.zWindX+vWind*vTimeDelta
)
);
Set(vPathX,
If(recLast.zPathX<0,
0,
recLast.zPathX+((vVelX+(vForceX/vMas)*vTimeDelta)*vTimeDelta)+(vForceX/vMas)*vTimeDelta^2
)
);
Set(LstY,recLast.zPathY-recRocket.Elev);
Set(py,LstY+vVelY*vTimeDelta+(0.5*vAccelY)*(vTimeDelta^2));
If(py>0,
Set(vPY,py),
Set(vPY,0)
);
Set(vPH,Sqrt(vPathX^2)+(vPY^2)));
If((vPY-recRocket.Elev)<recRocket.Rod,
Switch(varTrajNo,1,Set(vAng,vLAngle),2,Set(vAng,vLAngle),3,Set(vAng,vFailAngle)),
If(vVelY=0,
Set(vAng,Pi()/2),
If(vVelY>0,
Set(vAng,Atan(vVelX/vVelY)),
Set(vAng,Atan(vVelX/vVelY)+Pi())
)
)
);
If(!blApogee,
If(vPY<LstY,
Set(dApogee,LstY+recRocket.Elev);
Set(blApogee, true );
Set(vApogeeTime,vCounter-vTimeDelta)
)
);

If(And(blApogee,(vPY<=0)),
Set(dDist,vWindX);
Set(blFinished, true )
);

If(xLineNo=15,
Set(blFinished, true )
);

Collect(clTraj,
{
zLineNo: xLineNo,
zTimeCounter: vCounter,
zRho: vRho,
zSFCarea: vSFC,
zAngle: vAng,
zCOEFF: vCF,
zDragX: vDragX,
zDragY: vDragY,
zDrag: vdg,
zThrust: vTH,
zThrustX: vThrX,
zThrustY: vThrY,
zPathX: vPathX,
zPathY: vPY,
zPath: vPH,
zGravityX: vGX,
zTotalMass: vMas,
zGravityY: vGY,
zForceX: vForceX,
zForceY: vForceY,
zForce: vForce,
zAccelX: vAccelX,
zAccelY: vAccelY,
zAccel: vAccel,
zVelocityX: vVelX,
zVelocityY: vVelY,
zVelocity: vVel,
zWind: vWind,
zWindX: vWindX,
zDist: dDist,
zChuteOpen: vParaOpen,
zApogeeReached: blApogee,
zApogee: dApogee,
zApogeeTime: vApogeeTime,
zStage: vstage,
zFinished: blFinished
}
);
Select(Loop)

Categories:
  • Gerard Simpson Profile Picture
    2,987 Moderator on at

    Hi @Anonymous 

     

    UPDATE

    I need to correct my previous post - I tried your ClearCollect function on its own with some dummy data and it works fine.

     

    You mentioned that all your Set functions work fine and give the correct results, so I wonder is it something to do with how Power Apps handles so many sequential functions/variables that are then collected below. Are there any of your Set functions that can be undertaken simultaneously?- if so, may be try wrapping them in a 'Concurrent' function to cut down the time to run the entire expression and see if that helps.

     

    Also maybe try adding a test timer to create a 1 or 2 second lag between end of the last Set and your ClearCollect.

     

    Lastly, it may be worth exploring the 'With' function as it's quite good at handling scenarios like this where variables are set and re-used in the context of the running expression only. This would require a re-write of the expression, but it should enable you to refine things down quite a bit.

     

    Hope this helps in some way - Good luck

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 354 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 330

#3
Mohsin Ali Profile Picture

Mohsin Ali 232

Last 30 days Overall leaderboard