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
haykp
Helper I
Helper I

Merge 2 columns and find the common values

Dear Community,

 

I am freshmen in PowerBI, please help to solve one task with powerBI.

So I have 2 different lists with {Code,Price} values.

I need to compare these lists i.e.

a) find all elements with same Code and compare the prices

b) find all missing elements in List1

c) find all extra elements in List1

 

I think these 3 items are someohow connected, thats why writing in one topic.

These are my lists example:

 

Lists1:

haykp_0-1682704191996.png

List2:

haykp_1-1682704211173.png

 

Can someone please point me what direcction to go?

 

Thanks

Hayk

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@haykp Maybe:

Calculated Table Missing List 1 =
  VAR __List1 = SELECTCOLUMNS('List1', "__Code", [Code])
  VAR __List2 = SELECTCOLUMNS('List1', "__Code", [Code])
  VAR __Return = EXCEPT(__List1, __List2)
RETURN
  __Result



Calculated Table Missing List 2 =
  VAR __List1 = SELECTCOLUMNS('List1', "__Code", [Code])
  VAR __List2 = SELECTCOLUMNS('List1', "__Code", [Code])
  VAR __Return = EXCEPT(__List2, __List1)
RETURN
  __Result



Compare Measure =
  VAR __Code = MAX('List1'[Code]) //assumes List1[Code] is in your visual
  VAR __Price = MAX('List1'[Price])
  VAR __Price2 = MAXX(FILTER('List2', [Code] = __Code), [Price])
  VAR __Result = __Price - __Price2
RETURN
  __Result

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

@haykp Maybe:

Calculated Table Missing List 1 =
  VAR __List1 = SELECTCOLUMNS('List1', "__Code", [Code])
  VAR __List2 = SELECTCOLUMNS('List1', "__Code", [Code])
  VAR __Return = EXCEPT(__List1, __List2)
RETURN
  __Result



Calculated Table Missing List 2 =
  VAR __List1 = SELECTCOLUMNS('List1', "__Code", [Code])
  VAR __List2 = SELECTCOLUMNS('List1', "__Code", [Code])
  VAR __Return = EXCEPT(__List2, __List1)
RETURN
  __Result



Compare Measure =
  VAR __Code = MAX('List1'[Code]) //assumes List1[Code] is in your visual
  VAR __Price = MAX('List1'[Price])
  VAR __Price2 = MAXX(FILTER('List2', [Code] = __Code), [Price])
  VAR __Result = __Price - __Price2
RETURN
  __Result

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

@haykp , you can merge the two table in power query using full outer or left anti to check what is missing

 https://radacad.com/append-vs-merge-in-power-bi-and-power-query

 

Or create a common table code from both tables and then you can compare there price using measures

Power BI- DAX: When I asked you to create common tables: https://youtu.be/a2CrqCA9geM
https://medium.com/@amitchandak/power-bi-when-i-asked-you-to-create-common-tables-a-quick-dax-soluti...

 

Power BI- Power Query: When I asked you to create common tables: https://youtu.be/PqfGW6pl1Sw

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.