cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
gerard-kouadio
Frequent Visitor

create new column from 2 tables using if function

Hello, I have 2 tables and I want to create a column from the ids of the 2 tables. I want to do something like this:

if id of table 1 = id of table 2, put yes, if no, put No.

NB: there is a many-to-many relationship in the tables

 

Thank you for your help !

2 ACCEPTED SOLUTIONS
v-luwang-msft
Community Support
Community Support

HI  @gerard-kouadio ,

Pls refer the below sample:

tableA:

vluwangmsft_0-1668395169758.png

Table B:

vluwangmsft_1-1668395238213.png

 

Column = 
var Q1 = TableA[ID]
var NewCol = CALCULATE(MAX('Tableb'[ID]),Tableb[ID]=Q1)
return IF(NewCol<>BLANK(),1,BLANK())

vluwangmsft_2-1668395472225.png

 

 

Best Regards

Lucien

View solution in original post

gerard-kouadio
Frequent Visitor

I finally used this code:
New colomn = if(ISBLANK(LOOKUPVALUE('Table1'[Id], 'Table1'[Id],Table2[Id])),"Non","Oui")

View solution in original post

6 REPLIES 6
gerard-kouadio
Frequent Visitor

I finally used this code:
New colomn = if(ISBLANK(LOOKUPVALUE('Table1'[Id], 'Table1'[Id],Table2[Id])),"Non","Oui")
mariussve1
Solution Supplier
Solution Supplier

Hi,

This could also work:

Column =
VAR _Lookup = [Product]
RETURN
IF (
ISBLANK ( LOOKUPVALUE ( Table2[Product], Table2[Product], _Lookup ) ),
"No",
"Yes"
)

Thennarasu_R
Responsive Resident
Responsive Resident

Hi,

Measure=IF(SELECTEDVALUE(TAble1 [ID])=SELECTEDVALUE(TAble2 [ID]),"YES","NO")

Thanks,
Thennarasu

v-luwang-msft
Community Support
Community Support

HI  @gerard-kouadio ,

Pls refer the below sample:

tableA:

vluwangmsft_0-1668395169758.png

Table B:

vluwangmsft_1-1668395238213.png

 

Column = 
var Q1 = TableA[ID]
var NewCol = CALCULATE(MAX('Tableb'[ID]),Tableb[ID]=Q1)
return IF(NewCol<>BLANK(),1,BLANK())

vluwangmsft_2-1668395472225.png

 

 

Best Regards

Lucien

Mikelytics
Resident Rockstar
Resident Rockstar

Hi @gerard-kouadio,

 

Can you please show a picture of the data model as well as explain how you want to visualize it? Which visual do you want to use and which columns do you also want to put into the visual?

 

Best regards

Michael

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!
mariussve1
Solution Supplier
Solution Supplier

Hi,

 

I think you can achive this by using methods explained in this article:

https://www.sqlbi.com/articles/from-sql-to-dax-joining-tables/

Without knowing your data or model I think you should look at the selectcolumns and natural join, treatas and/or lookup.

 

And at the end combine this with IF or maybe switch.

 

Br

Marius

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors