Forum Discussion
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
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
4 Replies
- AnonymousNot 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
- v-jiascu-msftMicrosoft Employee
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
- AnonymousNot applicable
Thanks a lot Dale!
Works like a charm.
Kind regards,
Igor