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
ElliotPrime
New Member

Create a SUM measure that sums conditionally based on 2 tables

Hello,

 

I have a relation between 2 tables on the index columns and I want to create a SUM that would look like this :

CALCULATE(SUM(Table1[Value]) / DISTINCTCOUNT(Table1[Number]), Table1[Number] = Table2[Number])

 

This command does not work so I wanted to know if it was possible to do something like this.

 

Thank you

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @ElliotPrime ,

 

Here are the steps you can follow:

1. Create calculated column.

Average =
var _count=
COUNTX(FILTER(ALL(Table1),'Table1'[WeekNum]=EARLIER('Table2'[WeekNum])),[WeekNum])
var _sum=
SUMX(FILTER(ALL(Table1),'Table1'[WeekNum]=EARLIER('Table2'[WeekNum])),[Value])
return
DIVIDE(_sum,_count)

2. Result:

vyangliumsft_0-1670810429249.png

 

Best Regards,

Liu Yang

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

3 REPLIES 3
Anonymous
Not applicable

Hi  @ElliotPrime ,

 

Here are the steps you can follow:

1. Create calculated column.

Average =
var _count=
COUNTX(FILTER(ALL(Table1),'Table1'[WeekNum]=EARLIER('Table2'[WeekNum])),[WeekNum])
var _sum=
SUMX(FILTER(ALL(Table1),'Table1'[WeekNum]=EARLIER('Table2'[WeekNum])),[Value])
return
DIVIDE(_sum,_count)

2. Result:

vyangliumsft_0-1670810429249.png

 

Best Regards,

Liu Yang

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

Greg_Deckler
Community Champion
Community Champion

@ElliotPrime Try:

Measure 4 = 
    VAR __Table = FILTER('Table6',RELATED(Table7[Index]) <> BLANK())
    VAR __Result = DIVIDE( SUMX(__Table, [Value]), COUNTROWS(DISTINCT(__Table)) )
RETURN
    __Result


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hey @Greg_Deckler 

 

Thank you for you answer but the result is not quite what I want... Let me illustrate what I want (I made these tables on Excel to be clearer) :

My first table (Table1) looks like this (It is a value associate to a day in a week) :

Table1Table1

I want my second table (Table2) to look like this :

Table2Table2

As you can see, I want to take every values from the Table1 where 'WeekNum' is equal to 'WeekNum' in Table2 and find the average. Here for example, (345 + 324 + 325 + 657 + 865) / 5 = 503,2

 

My 2 tables already have a relation between them by an index column. Is it possible to not create a measure but a column with this average ?

 

Thank you

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 Kudoed Authors