I was able to fix my filter and I have to say, Power Apps is the stupidest piece of tech I had a chance to work with. It starts to boil my blood when I see all these Microsoft execs saying how low code is great. Look at the first snipped of code (issues with delegation) vs second piece of code. Ok, I get it, delegation is not supported if I use ID > 0 but still, even without it, it did not work and I had to rewrite it into that monstrosity below. My requirements were simple:
- if you are an admin, I will show you all records, otherwise I will show you records only for a signed in user
- if status dropdown is selected, I will filter by text column in SPO otherwise, I will not filter by it
Microsoft people should be paying us for being forced with such a mediocre tech
From this
SortByColumns(
Filter(
ZmluvySchvalovania,
//filter only records for the current user
If(
var_admin,ID > 0,ThisRecord.Gestor.Email = User().Email || ThisRecord.GestorDabler.Email = User().Email
),
//filter records based on status
If(
dd_status_filter_1.Selected.InternalName = "All",ID > 0,ThisRecord.Status = Value(dd_status_filter_1.Selected.InternalName)
),
If(
IsBlank(txt_filter_1.Text), ID > 0, txt_filter_1.Text in Title
) // filter recored based on text search
),
"Created",
If(dd_status_filter_created_1.Selected.Value = "Najnovšie","Descending","Ascending")
)
To This
With(
{
_items:
If(
var_admin && dd_status_filter_1.Selected.Value <> 0,
//if admin and STATUS filter ON
Filter(
ZmluvySchvalovania,
ThisRecord.Status = dd_status_filter_1.Selected.Value,
IsBlank(txt_filter_1.Text) || StartsWith(Title,txt_filter_1.Text)
)
,
//if admin and no filter
If(
var_admin && dd_status_filter_1.Selected.Value = 0,
Filter(
ZmluvySchvalovania,
IsBlank(txt_filter_1.Text) || StartsWith(Title,txt_filter_1.Text)
)
,
//if NOT admin and STATUS filter ON
!var_admin && dd_status_filter_1.Selected.Value <> 0,
Filter(
ZmluvySchvalovania,
ThisRecord.Status = dd_status_filter_1.Selected.Value,
IsBlank(txt_filter_1.Text) || StartsWith(Title,txt_filter_1.Text),
ThisRecord.Gestor.Email = User().Email || ThisRecord.GestorDabler.Email = User().Email
)
,
//if NOT admin and STATUS filter OFF
Filter(
ZmluvySchvalovania,
IsBlank(txt_filter_1.Text) || StartsWith(Title,txt_filter_1.Text),
ThisRecord.Gestor.Email = User().Email || ThisRecord.GestorDabler.Email = User().Email
)
)
)
},
SortByColumns(
_items,
"Created",
If(dd_status_filter_created_1.Selected.Value = "Najnovšie","Descending","Ascending")
)
)