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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
kushalt1996
Frequent Visitor

Populate first value with the expanded column's value and rest with 0/null on merge query

I have two tables 

Table A - Has Product information (Product, Sub-Product Count)

Table B - Actually it's a sales table with (Sales Date, Brand/Product)

 

Requirement - I want third column on merge. But I only want to have third column to have values (no. of sub-product) to be populated for only first matching Product/Brand and rest to be '0' or null for the same Brand/Product.

 

The merge operation is applied based on 'Left Join' on column 'Brand' : Table B -> Table A 

 

values required.png

1 REPLY 1
NaveenGandhi
Super User
Super User

Hello @kushalt1996 

 

I have a solution that involves PQ and DAX. Please follow the below.

Sep 1:

Add index to your table - b  And create a custom column by using [Brand]&Text.From([Index]).NaveenGandhi_0-1685376464368.png

Step 2:

Merge Table-b with table - a and pull the Min of index from Table - b. Again create a custom column like above.NaveenGandhi_3-1685376590030.png

 

Step 3:
Close and Apply and use a lookup to pull the Sub Product count.

No of Sub Product = LOOKUPVALUE('Table- A'[Sub-Product count],'Table- A'[Custom],'Table - B'[Custom])
NaveenGandhi_4-1685376787241.png

 

Please let me know this solution is good with you and if you have any questions.
 
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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