Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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

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

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

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.
Anonymous
Not applicable

Thanks a lot Dale!

 

Works like a charm.

 

Kind regards,

Igor

Anonymous
Not applicable

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.