Ambiguity

Recently I was asked about issues related to ambiguity in Power Apps code. In this post I will look at how to avoid any ambiguity issues in Power Apps.

Ambiguity

First of all what is ambiguity? According to the dictionary, it is all about things not being clear as multiple explanations can be given to the same thing.

Ambiguity definition

Ok, that’s all great! But what does that have to do with Power Apps.

Power Apps and Ambiguity

I’m going to start by creating two collections. Using the following code I’m going to create a collection called colFruit:

ClearCollect(
    colFruit,
    {
        Type: "Apple",
        Colour: Green
    },
    {
        Type: "Apple",
        Colour: Red
    },
    {
        Type: "Plum",
        Colour: Red
    },
    {
        Type: "Plum",
        Colour: Yellow
    },
    {
        Type: "Banana",
        Colour: Yellow
    }
);

And for my second collection I’m going to created a collection of cars

ClearCollect(
    colCars,
    {
        Type: "Nissan",
        Colour: Red
    },
    {
        Type: "Volkswagen",
        Colour: Yellow
    },
    {
        Type: "Ford",
        Colour: Green
    }
);

Now using the colour of the cars, I want to suggest the fruits that share the same colour as the car.

Using the Ambiguity operator

A first attempt might give you code like this:

Ambiguity in Power Apps Microsoft Power Apps image 14

But the above code of course will not work.

Colour is the same as Colour as I’m not specifying where the Colours are coming from ( either the colFruit or colCars collections ) the expression doesn’t make much sense.

We can now let the expression make sense by changing the code a bit.

Ambiguity in Power Apps Microsoft Power Apps image 15
ClearCollect(
    colSuggestFruitByColour,
    ForAll (
        colCars,                    
            First(Filter(
                colFruit,
                Colour = colCars[@Colour] 
            ))
        )
    );

Using the above code, I can specify, the colCars collection used in the ForAll using the following syntax

Collection[@Property]

Using the above construction we can specify which of the datasources we want to use within the nested lines of code.

Avatar for Pieter Veenstra

By Pieter Veenstra

Business Applications and Office Apps & Services Microsoft MVP working as a Microsoft Productivity Principal Consultant at HybrIT Services. You can contact me using contact@veenstra.me.uk.

8 thoughts on “Ambiguity in Power Apps”
  1. That’s really useful, I’ve always used rename columns in instances like this to rename one of the Colour column and had no idea about this. I’ve never really fully understood the use of the @ in PowerApps. Although I’ve seen posts in forums with answers that say use [@] I’ve never understood why and it’s use is never covered in any online tutorials. This is the first time I’ve actually seen a use case for it, similarly for Power Automate, lots of examples of using it but never accompanied by an explanation of why or what it actually does. Does it have any other uses other than this kind of ambiguity?

    1. Hi Rob,

      It can in general be used when you want to be specific about what you want to select. Typically that happens in ForAll loops where you want to do something inside the forall loop.

  2. The disambiguation operator is pretty handy, but we also have the ThisRecord and As operators – https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/operators#thisitem-thisrecord-and-as-operators.
    I highly prefer them over the [@…] notation, as it results in more readable code.

    Are there in your opinion situations where the disambiguation operator is the only solution or the better solution? As I cannot easily think of a scenario.

    1. The as operator I can see as a good option quite often although I prefer to keep the original names of the collections/datasources. Using multiple names for the same thing can be confusing.

      Also in general the @ signs do take the attention of the reader. This tells me often, watch out there is something complicated here.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.