cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
v-jiascu-msft Super Contributor
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
)

IF_statement_combined_with_multiple_Lookupvalues_from_a_different_Table

 

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.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

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

Important addition:

 

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

v-jiascu-msft Super Contributor
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
)

IF_statement_combined_with_multiple_Lookupvalues_from_a_different_Table

 

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.

View solution in original post

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

hoodeamy Frequent Visitor
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!

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

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

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

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.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

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

Users Online
Currently online: 45 members 922 guests
Please welcome our newest community members: