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 / Variables not showing ...
Power Apps
Unanswered

Variables not showing the right value

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi everyone,

I have these variable on my App OnStart:

 

Set(gblHoraEntrada, LookUp(Horarios, Tipo = LookUp(Departamento, Departamento = gblUserDepartamento.Value).Tipo_Horario.Value).horaEntrada),
 Set(gblHoraSaida, LookUp(Horarios, Tipo = LookUp(Departamento, Departamento = gblUserDepartamento.Value).Tipo_Horario.Value).horaSaida),
 Set(gblHoraInicioAlmoco, LookUp(Horarios, Tipo = LookUp(Departamento, Departamento = gblUserDepartamento.Value).Tipo_Horario.Value).horaInicioAlmoco),
 Set(gblHoraFimAlmoco, LookUp(Horarios, Tipo = LookUp(Departamento, Departamento = gblUserDepartamento.Value).Tipo_Horario.Value).horaFimAlmoco),

 Set(gblTipo_Horario, First(Horarios).Tipo),
 Set(gblResponsavel, First(Equipa).Nome),

 

Then I'm trying to calculate the difference between two date and times, but my variables are always with the default values and are not dynamic. What am I doing wrong?

 

If(
 start_DataCard3.Update < end_DataCard3.Update && DateDiff(start_DataCard3.Update, end_DataCard3.Update, TimeUnit.Days) <= 30, 
 With({
 varHourRange: 
 AddColumns(
 ForAll(
 Sequence(
 DateDiff(
 start_DataCard3.Update,
 If(DataCardValue20.Value, 
 DateAdd(end_DataCard3.Update, 1, TimeUnit.Minutes),
 end_DataCard3.Update
 ),
 TimeUnit.Minutes
 )
 ),
 DateAdd(start_DataCard3.Update, Value -1, TimeUnit.Minutes)
 ),
 "Horas",
 (Hour(Value) + Minute(Value) / 60)
 ) 
 },
 CountIf(
 varHourRange,
 If(gblMotivoSelecionado = "Overtime",
 Or(
 Horas < gblHoraEntrada, 
 Horas >= gblHoraSaida, 
 Weekday(Value) in [1, 7], 
 Year(Value)*10000+Month(Value)*100+Day(Value) in colFeriados.DataInteiro
 ),
 And(
 Or(
 And(Horas >= gblHoraEntrada, Horas < gblHoraInicioAlmoco), 
 And(Horas >= gblHoraFimAlmoco, Horas < gblHoraSaida) 
 ),
 Weekday(Value) in [2, 3, 4, 5, 6], // dias da semana
 Not(Year(Value)*10000+Month(Value)*100+Day(Value) in colFeriados.DataInteiro)
 )
 )
) / 60 / 8
 
 )
)

 

Categories:
  • gcmfaizan Profile Picture
    1,022 on at

    Hi @Rui_Couto ,

     

    In your OnStart formula, you're setting the global variables based on certain LookUp functions. It seems like the values for these global variables are dependent on other values in your data, but they are set only once when the app starts. 

    Here are a few steps you could consider:

    1. Debugging the Global Variables:  By dividing the code into pieces and for debugging I recommend you to use button control and use Notify function to populate the value on top.

    2. Dynamic Updates:

      If the values of these global variables need to change dynamically based on user actions or other factors, you might need to update them in response to those changes. This could involve using Set statements for inappropriate events (e.g., button clicks, data updates) rather than just in the OnStart.

    Regards,

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 411 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 338

#3
WarrenBelz Profile Picture

WarrenBelz 256 Most Valuable Professional

Last 30 days Overall leaderboard