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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Jpalji
Frequent Visitor

Compare columns in power BI

Hi,

 

I have to create a new column(col4), when Col1 cell match's with Col3 cell then Col4 should create and data from Col2 as shown below (Col1 has ref2 and Col3 has Ref2 as there is a match Col4 should Col2 Value 20), Please advise me in this. Thanks in advance.

How can we create in Power BI desktop?

Capture.PNG

 

 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @Jpalji ,

 

You have 2 options trough the Query editor or in DAX.

 

DAX:

  • Add the following column to the table:
Col4 = LOOKUPVALUE('Table'[Col2];'Table'[Col1];'Table'[Col3])

Query Editor:

  • Do a merge of the table with itself
  • On the merge you should match the Col3 with Col1 left outer join on col3
  • Expand the resulting column and select col2 then rename:
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkpNM1TSUTI0MACSQI6RUqxONISho2QEEoQJGAPZpqYQVWYwQRMg39wCSRVIgaUhkoAZkG1iChaIBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", Int64.Type}, {"Column3", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Column3"}, #"Changed Type", {"Column1"}, "Changed Type", JoinKind.LeftOuter),
    #"Expanded Changed Type" = Table.ExpandTableColumn(#"Merged Queries", "Changed Type", {"Column2"}, {"Changed Type.Column2"})
in
    #"Expanded Changed Type"

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

4 REPLIES 4
MFelix
Super User
Super User

Hi @Jpalji ,

 

You have 2 options trough the Query editor or in DAX.

 

DAX:

  • Add the following column to the table:
Col4 = LOOKUPVALUE('Table'[Col2];'Table'[Col1];'Table'[Col3])

Query Editor:

  • Do a merge of the table with itself
  • On the merge you should match the Col3 with Col1 left outer join on col3
  • Expand the resulting column and select col2 then rename:
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkpNM1TSUTI0MACSQI6RUqxONISho2QEEoQJGAPZpqYQVWYwQRMg39wCSRVIgaUhkoAZkG1iChaIBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", Int64.Type}, {"Column3", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Column3"}, #"Changed Type", {"Column1"}, "Changed Type", JoinKind.LeftOuter),
    #"Expanded Changed Type" = Table.ExpandTableColumn(#"Merged Queries", "Changed Type", {"Column2"}, {"Changed Type.Column2"})
in
    #"Expanded Changed Type"

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Jpalji
Frequent Visitor

Hi MFelix,

Thanks for reply, when I try to create a dax query as suggested power is showing error "A table of multiple values was supplied where a single value was expected". Please advise.

Thanks in advance.

Hi @Jpalji ,

 

Are you creating a column or a measure?

 

This is a column to be created on your table not a measure.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Jpalji
Frequent Visitor

Hi @MFelix ,

 

I have created a column but it is throwing the same error, but it worked when I duplicated table and created a column as advised.

Thanks a lot, @MFelix . 

 

Have a nice weekend!!

 

Once again thanks.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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