Forum Discussion
If statement more than one table
I need help with multiple table If statement, I tried to give sample tables below.
If Column Code=100 then the new column should be XYZ else if the Column is Grp is 8fni then it should be ABC, the rest are EFG
Table 1:
| Code | Sales | DAX HELP! |
| 100 | 190 | |
| 102 | 93 | |
| 109 | 89 | |
| 200 | 93 | |
| 290 | 9 | |
| 100 | 39 | |
| 100 | 89 | |
| 200 | 99 | |
| 100 | 20 | |
| 290 | 289 | |
| 102 | 98 | |
| 109 | 78 | |
| 200 | 398 | |
| 102 | 92 | |
| 100 | 83 | |
| 109 | 109 |
Table 2:
| key | Grp |
| a | 0so |
| b | 0dk0 |
| c | 0kis |
| d | 8vhi |
| e | 8fni |
| f | 8hf8 |
Hey powerbihelp87 ,
yes, you can write it like that:
DAX Help Column = SWITCH( TRUE(), 'Table 1'[Code] = "100", "XYZ", RELATED( 'Table 2'[Grp] ) IN { "8fni", "8vhi", "0kis" }, "ABC", "EFG" )By the way, always link someone in an answer like that: powerbihelp87
Otherwise I won't get a notification that you answered.
If you need any help please let me know.If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍Best regardsDenisBlog: WhatTheFact.biFollow me: twitter.com/DenSelimovic
6 Replies
- parry2k
Super User
powerbihelp87 not really clear what you are looking for? How these tables are connected? What is your expected output give the logic you explained. The most critical part is how these tables are connected.
- powerbihelp87
Helper V
selimovd parry2k I was missing the Code column in the example Table 2 to show they are related, I was able to figure out the formula I needed below. It works fine. I am trying to see how to write multiple options if the IF Related portion of the formula.
DAX Help Column =IF(Table 1[Code]="100", "XYZ",IF(RELATED(Table 2[Grp]="8fni","ABC","EFG" ))
- selimovd
Most Valuable Professional
Hey powerbihelp87 ,
sure, next time just give more details.
You can make it more readable with a SWITCH/TRUE:
DAX Help Column = SWITCH( TRUE(), 'Table 1'[Code] = "100", "XYZ", RELATED( 'Table 2'[Grp] ) = "8fni", "ABC", "EFG" )If you need any help please let me know.If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍Best regardsDenisBlog: WhatTheFact.biFollow me: twitter.com/DenSelimovic
- selimovd
Most Valuable Professional
Hey powerbihelp87 ,
logically it doesn't really make sense.
A calculated column always has to be in a specific table.
You are asking to put "XYZ" when a column from Table 1 has a value and "ABC" when the column of another table is a specific value. How are they connected?
Please explain a little better.
Best regards
Denis