Power Apps formula in gallery to apply condition

brendalpzm

Board Regular
Joined
Oct 3, 2022
Messages
59
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
Platform
  1. Windows
I am making a booking system for what I am developing a weekly view calendar, I am creating a gallery for the headers of this calendar.

The thing is that in the calendar some months contain a few days from other months, like the follwing picture

1706714012913.png

as you see the month is January (Enero) and there are 3 days of February showing. As shown in the picture, the logic I want to apply is whenever the days doesn't belong to the selected month on top, to specify the month of those days only between parethesis ( ), I have been trying a lot of things to get it right, 2 days of trying and still can figure it out. Could you help me out with this?

I attach the code I am using as well

Power Query:
If(Month((DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days)))=Month((DateAdd(_FirstDayofWeek-1,ThisItem.Value-2,TimeUnit.Days))),

///If it's the same month as the month selected
(If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dddd"))="Saturday",
"Sábado "&(Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dd")),
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dddd"))="Sunday",
"Domingo "&(Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dd")),
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dddd"))="Monday",
"Lunes "&(Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dd")),
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dddd"))="Tuesday",
"Martes "&(Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dd")),
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dddd"))="Wednesday",
"Miércoles "&(Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dd")),
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dddd"))="Thursday",
"Jueves "&(Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dd")),
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dddd"))="Friday",
"Viernes "&(Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dd")))))))))),

///If it is not the same month
(If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dddd"))="Saturday",
"Sábado "&(Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dd")),
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dddd"))="Sunday",
"Domingo "&(Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dd")),
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dddd"))="Monday",
"Lunes "&(Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dd")),
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dddd"))="Tuesday",
"Martes "&(Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dd")),
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dddd"))="Wednesday",
"Miércoles "&(Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dd")),
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dddd"))="Thursday",
"Jueves "&(Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dd")),
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dddd"))="Friday",
"Viernes "&(Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"dd"))))))))))&" ("&(If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Jan","Ene)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Feb","Feb)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Mar","Mar)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Apr","Abr)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="May","May)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Jun","Jun)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Jul","Jul)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Aug","Ago)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Sep","Sep)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Oct","Oct)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Nov","Nov)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Dec","Dic)",""))))))))))))))
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
You can get the month using Switch:

Excel Formula:
SWITCH(Month(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),1,"Ene)",4,"Abr)",8,"Ago)",12,"Dic)",Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))

For the check, you could probably just test if the relevant date value formatted as mmmm yyyy matches your selected month.
 
Upvote 0
You can get the month using Switch:

Excel Formula:
SWITCH(Month(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),1,"Ene)",4,"Abr)",8,"Ago)",12,"Dic)",Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))

For the check, you could probably just test if the relevant date value formatted as mmmm yyyy matches your selected month.
So basically I replace the first line with the fornula you sent?
 
Upvote 0
No, that replaces the part at the end that adds the month name suffix:

Excel Formula:
(If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Jan","Ene)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Feb","Feb)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Mar","Mar)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Apr","Abr)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="May","May)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Jun","Jun)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Jul","Jul)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Aug","Ago)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Sep","Sep)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Oct","Oct)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Nov","Nov)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Dec","Dic)","")))))))))))))
 
Upvote 0
No, that replaces the part at the end that adds the month name suffix:

Excel Formula:
(If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Jan","Ene)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Feb","Feb)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Mar","Mar)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Apr","Abr)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="May","May)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Jun","Jun)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Jul","Jul)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Aug","Ago)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Sep","Sep)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Oct","Oct)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Nov","Nov)",
If((Text(DateAdd(_FirstDayofWeek-1,ThisItem.Value,TimeUnit.Days),"mmm"))="Dec","Dic)","")))))))))))))
I am afraid I am not understanding,

That part works fine but the thing is that I only want it to show on the months that don't belong to the selected one at the top
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,179
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top