cancel
Showing results for
Did you mean:
Anonymous
Not applicable

IF statement combined with multiple Lookupvalues from a different Table

I try to find my answer online, but after a day without success I hope that maybe one of you can help me with my issue.

What I try to do is: if a field has a value that can be found in that other table, it

So let's say this is the main data set I have right now:

MainTable

Columns:

Supermarket, AppleSize, BananaSize

Supermarket1, Big, Big

Supermarket2, Big, XXL

Supermarket3, Small, XL

Supermarket4, Little, XXL

And in another table we have all values the supermarkets can choose:

FruitTable

Columns:

Category,Type,Size

Fruit, Apple, Big

Fruit, Apple, Small

Fruit, Apple, Normal

Fruit, Banana, Big

Fruit, Banana, XXL

You see now that in my main data set,:

Supermarket4 gave the wrong value for the size of the apples they sell (Little, while only Big, Small or Normal are allowed)

Supermarket3 gave the wrong value for the size of the bananas they sell (XL, while only Big or XXL are allowed)

What I want is to measure how many % is correctly filled in, and with bare eyes you can see that for the applesize 75% is correctly filled in and the same goes for bananas. However, how to calculate this?

What I want to do is add a new calculated colum with an IF statement in it: IF the value 'Big' is found in the 'Fruittable' for type 'Apple', then say "Yes", else "No". Then I can count the y/n's to get the % out of it.

All the help, greatly appreciated!

Kind regards,

Igor

1 ACCEPTED SOLUTION

Accepted Solutions
Super Contributor

Re: IF statement combined with multiple Lookupvalues from a different Table

Hi Igor,

Add these two calculated columns please. Then calculating the % would be easy.

```AppleCheck =
VAR appleSizes =
CALCULATETABLE ( VALUES ( FruitTable[Size] ), 'FruitTable'[Type] = "Apple" )
RETURN
IF ( [AppleSize] IN appleSizes, "Yes", "No" )```
```BananaCheck =
VAR BananaSizes =
CALCULATETABLE ( VALUES ( FruitTable[Size] ), 'FruitTable'[Type] = "Banana" )
RETURN
IF ( [BananaSize] IN BananaSizes, "Yes", "No" )```
```% =
DIVIDE (
CALCULATE ( COUNT ( MainTable[AppleCheck] ), MainTable[AppleCheck] = "Yes" ),
COUNT ( MainTable[AppleCheck] ),
0
)```

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 REPLIES 4
Anonymous
Not applicable

Re: IF statement combined with multiple Lookupvalues from a different Table

You could say something  like this (probably not entirely correct)

IF( FruitTable[Apple] = "Big" || "Small" || "Yes"; "Yes"; "No"

But it has to lookup the values which are allowed from that table, since you don't want to change all the calculated columns' IF statements, when the possible allowed values in the FruitTable are extended.

Kind regards,

Igor

Super Contributor

Re: IF statement combined with multiple Lookupvalues from a different Table

Hi Igor,

Add these two calculated columns please. Then calculating the % would be easy.

```AppleCheck =
VAR appleSizes =
CALCULATETABLE ( VALUES ( FruitTable[Size] ), 'FruitTable'[Type] = "Apple" )
RETURN
IF ( [AppleSize] IN appleSizes, "Yes", "No" )```
```BananaCheck =
VAR BananaSizes =
CALCULATETABLE ( VALUES ( FruitTable[Size] ), 'FruitTable'[Type] = "Banana" )
RETURN
IF ( [BananaSize] IN BananaSizes, "Yes", "No" )```
```% =
DIVIDE (
CALCULATE ( COUNT ( MainTable[AppleCheck] ), MainTable[AppleCheck] = "Yes" ),
COUNT ( MainTable[AppleCheck] ),
0
)```

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Anonymous
Not applicable

Re: IF statement combined with multiple Lookupvalues from a different Table

Thanks a lot Dale!

Works like a charm.

Kind regards,

Igor

Frequent Visitor

Re: IF statement combined with multiple Lookupvalues from a different Table

Hi,

I think this is similar as it involves an IF statement that references more than 1 table.

So, in this basic example I have 2 tables and want to say something like:

IF( Table1[ColumnA] = "XXX" && Table2[ColumnB] = "YYY", "Result A", "Result B")

In my real example both Table 1 and Table 2 have a direct relationship with a master table, so an indirect relationship with each other. I have also tried a simplified version with the same data, just these 2 tables with a many to many relationship to see if that made it any easier but it hasn't!

I am not sure if you do this another way in Power BI as I can't seem to find an easy solution anywhere?

Any help appreciated! Thanks!

Announcements

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Get your latest community news and announcements.

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Top Kudoed Authors
Users Online
Currently online: 45 members 922 guests
Recent signins: