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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
stevencsh
Regular Visitor

Merging different criteria as one final value

Hi guys,

In this fact table, I'd like to achieve the result in the column "Merge Product":

stevencsh_0-1624531082315.png

 

Here're the criteria:

- If Product A & B exists in the same Document No, AND
- Product A & B "Quantity" is the same, AND
- Product A & B "Order Type" is the same

Then Merge Product = B, else remain as "Product"

 

How can I achieve above using DAX formulas? Thank you for your help in advance!

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@stevencsh 
Add the following code as a new column:

New Column = 
var __t = SELECTCOLUMNS( FILTER( ALL(Table2) , Table2[Document No] = EARLIER(Table2[Document No]) && Table2[Quantity] = EARLIER(Table2[Quantity]) && Table2[Order Type]=EARLIER(Table2[Order Type] )),"Prod" , Table2[Product] ) return

IF( "A" in __t && "B" in __t , "B" , Table2[Product] )

Fowmy_0-1624532767624.png

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

5 REPLIES 5
Fowmy
Super User
Super User

@stevencsh 
Add the following code as a new column:

New Column = 
var __t = SELECTCOLUMNS( FILTER( ALL(Table2) , Table2[Document No] = EARLIER(Table2[Document No]) && Table2[Quantity] = EARLIER(Table2[Quantity]) && Table2[Order Type]=EARLIER(Table2[Order Type] )),"Prod" , Table2[Product] ) return

IF( "A" in __t && "B" in __t , "B" , Table2[Product] )

Fowmy_0-1624532767624.png

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy, there is a change in the requirement as follow:

 

stevencsh_1-1625057139488.png

Previous scenario:

- If Product A & B exists in the same Document No, AND
- Product A & B "Quantity" is the same, AND
- Product A & B "Order Type" is the same

Then Merge Product = B, else remain as "Product"

 

Additional scenario:

- If Product A & B exists in the same Document No, AND
- Product A "Quantity" <> Product B "Quantity", AND
- Product A "Order Type" <> Product B "Order Type"

Then Merge Product = B, else remain as "Product" (This would be the one circled in red). Notice that in row #3 it should still remain as A.

 

How can we modify the previous formula to achieve the new scenario?

 

You are the saviour! It works perfectly!! 😍 Thank you so much!

 

A question about your formula, what is the "Prod" used for?

@stevencsh 

 

Prod is the name I gave for the Product column which is required by  the SELECTCOLUMNS  function, it extracts the Product Column after the FILTER has done its job

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

I see. Thanks for your clarification! Appreciate that.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors