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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Sergei8000
New Member

Splitting values where keys matching

I have two tables. In table 1 there is about 800 repeating key values. In table 100 unique key values and 20 columns with data values.

I want output where each matching value splitted by number of matches.

Table 1
id
A
B
A
C
A
A
C

 

Table 2   
unique_idCol1Col2Col3
A40010020
B200 800
C600800 

 

output   
idCol1Col2Col3
A100255
B200 800
A100255
C300400 
A100255
A100255
C300400 

 

How to achieve this?

2 ACCEPTED SOLUTIONS
Dangar332
Super User
Super User

hi, @Sergei8000 

try below

 

Column 1= 
 var a = CALCULATE(SUM('Table 2'[Col1]))
 var b = CALCULATE(COUNT('Table 1'[id]))
  return
  DIVIDE(a,b)

 

repeat for all column

View solution in original post

v-tangjie-msft
Community Support
Community Support

Hi @Sergei8000 ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create calculated columns.

Col 1 = 
 var a = CALCULATE(SUM('Table 2'[Col1]),FILTER('Table 2','Table 2'[unique_id]=EARLIER('Table 1'[id])))
 var b = COUNTROWS(FILTER('Table 1','Table 1'[id]=EARLIER('Table 1'[id])))
  return
  DIVIDE(a,b)
Col 2 = 
 var a = CALCULATE(SUM('Table 2'[Col2]),FILTER('Table 2','Table 2'[unique_id]=EARLIER('Table 1'[id])))
 var b = COUNTROWS(FILTER('Table 1','Table 1'[id]=EARLIER('Table 1'[id])))
  return
  DIVIDE(a,b)
Col 3 = 
 var a = CALCULATE(SUM('Table 2'[Col3]),FILTER('Table 2','Table 2'[unique_id]=EARLIER('Table 1'[id])))
 var b = COUNTROWS(FILTER('Table 1','Table 1'[id]=EARLIER('Table 1'[id])))
  return
  DIVIDE(a,b)

(3) Then the result is as follows.

vtangjiemsft_0-1702540967738.png

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

View solution in original post

2 REPLIES 2
v-tangjie-msft
Community Support
Community Support

Hi @Sergei8000 ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create calculated columns.

Col 1 = 
 var a = CALCULATE(SUM('Table 2'[Col1]),FILTER('Table 2','Table 2'[unique_id]=EARLIER('Table 1'[id])))
 var b = COUNTROWS(FILTER('Table 1','Table 1'[id]=EARLIER('Table 1'[id])))
  return
  DIVIDE(a,b)
Col 2 = 
 var a = CALCULATE(SUM('Table 2'[Col2]),FILTER('Table 2','Table 2'[unique_id]=EARLIER('Table 1'[id])))
 var b = COUNTROWS(FILTER('Table 1','Table 1'[id]=EARLIER('Table 1'[id])))
  return
  DIVIDE(a,b)
Col 3 = 
 var a = CALCULATE(SUM('Table 2'[Col3]),FILTER('Table 2','Table 2'[unique_id]=EARLIER('Table 1'[id])))
 var b = COUNTROWS(FILTER('Table 1','Table 1'[id]=EARLIER('Table 1'[id])))
  return
  DIVIDE(a,b)

(3) Then the result is as follows.

vtangjiemsft_0-1702540967738.png

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

Dangar332
Super User
Super User

hi, @Sergei8000 

try below

 

Column 1= 
 var a = CALCULATE(SUM('Table 2'[Col1]))
 var b = CALCULATE(COUNT('Table 1'[id]))
  return
  DIVIDE(a,b)

 

repeat for all column

Helpful resources

Announcements
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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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