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
Anonymous
Not applicable

SUMX calculation in the right context

Let me first explain the data structure. There is one table called Query with the following columns: 
"Ticker" (type=text) contains ticker names
"Bucket" (type=text) contains time buckets 00-01, 01-03, etc.
"ID" (type=text) contains a unique text string
"Score" (type=decimal number) contains decimal numbers
"Value" (type=decimal number) contains decimal numbers
A Ticker has several IDs. Every ID lies in a Bucket. Every ID has a Score and a Value.
 
In the following matrix visual I have represented several custom defined measures. The matrix has two levels (rows) which are expanded in the picture. The first level is Ticker and the second level is Bucket.
 
PBI_forum_picture.png
 
Weighted Average represents the Value weighted average Score of a Ticker overall or in a specific Bucket.
Weighted Market Average represents the Value weighted average Score of all Tickers overall or in a specific Bucket.
Weights w.r.t Ticker represents the Value weight of a Bucket with respect to a Ticker.
 
The measures are defined as follows:
 
 
Weighted Average = DIVIDE(SUMX(Query; Query[Score]*Query[Value]); SUM(Query[Value]))

Weighted Market Average = CALCULATE(DIVIDE(SUMX(Query; Query[Score]*Query[Value]); SUM(Query[Value])); ALL(Query[Ticker]))

Weights w.r.t Ticker = DIVIDE(SUM(Query[Value]); CALCULATE(SUM(Query[Value]); ALL(Query[Bucket])))

Bucket Weighted Ticker Average = SUMX(ALL(Query[Bucket]); Query[Weights w.r.t Ticker]*Query[Weighted Average])

Bucket Weighted Market Average = SUMX(ALL(Query[Bucket]); Query[Weights w.r.t Ticker]*Query[Weighted Market Average])
 
Currently, the measures "Bucket Weighted Ticker Average" and "Bucket Weighted Market Average" are not the way I would like them to be. 
On the Ticker level I want the measure "Bucket Weighted Market Average" to calculate the sum of the product of "Weights w.r.t Ticker" and "Weighted Market Average" over all available Buckets for a Ticker.
And on the Bucket level inside a Ticker I want the measure "Bucket Weighted Market Average" to calculate the sum of the product of "Weights w.r.t Ticker" and "Weighted Market Average" over the specific Bucket in the current context, hence the sum is only over one element and just the product.
 
I am aware that I am currently using ALL(Query[Bucket]) in the SUMX function such that I get the right value on the Ticker level but also the same values on the Bucket level.
How do I define the measure "Bucket Weighted Market Average" correctly in order to achieve my goal? How do I use SUMX? Over what table do I have to use SUMX?
 
The measure "Bucket Weighted Ticker Average" is analogous to "Bucket Weighted Market Average" where "Weighted Market Average" is replaced by "Weighted Average" in the measure definition.
 
My end goal is to represent the ratio (Bucket Weighted Ticker Average)/(Bucket Weighted Market Average) in an additional column.
1 ACCEPTED SOLUTION
v-cherch-msft
Employee
Employee

Hi @Anonymous 

 

It seems you may create a measure with ISFILTERED Function to change the total value for each dimension.You may have a look at below articles.

https://powerpivotpro.com/2013/03/hasonevalue-vs-isfiltered-vs-hasonefilter/

https://xxlbi.com/blog/new-dax-function-isinscope/

 

Regards,

Cherie

Community Support Team _ Cherie Chen
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-cherch-msft
Employee
Employee

Hi @Anonymous 

 

It seems you may create a measure with ISFILTERED Function to change the total value for each dimension.You may have a look at below articles.

https://powerpivotpro.com/2013/03/hasonevalue-vs-isfiltered-vs-hasonefilter/

https://xxlbi.com/blog/new-dax-function-isinscope/

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thanks a lot! I could solve my problem with HASONEFILTER.

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.