cancel
Showing results for
Did you mean:
Anonymous
Not applicable

## Cumulative DAX measure not based on calendar

Hello,

I am trying to write a measure which will yield the incremental totals for a visualisation.

Imagine this table:
Both tables are sorted by the % Pen high to low

 Product % Pen Prod1 3% Prod2 2,8% Prod3 1,4%

Now I would like to be able to add another column which tells me the incremental contribution of each product.

Here is an example:

 Product % Pen Incremental % Pen Prod1 3% 3% Prod2 2,8% 1,4% Prod3 1,4% 0,2%

The 'Incremental % Pen' column needs to filter away overlapping data between the earlier product and itself as to only present the actual contribution added by the product.

My data model has the following (relevant) tables:

I've tried searching for ways to do cumulative/incremental calculations, but what I find seems to be on a table level whereas I need it to be dynamic ie. calculated according to the products selected in the visualisation. I imagine I need a RANKX element to rank based on my [% Pen] measure along with some clever filters but I am in deep here to be quite honest.

I am having a difficult time figuring out how to crack this so please do ask for more info if something is needed. Any help would be much appreciated.

EDIT:
Here is my best attempt so far:

``````VAR _Rank = RANKX( ALLSELECTED( 'Product'[EAN] ) , CALCULATE( [Penetration] ) )

RETURN

CALCULATE(
[Penetration],
TOPN(
_Rank,
ALLSELECTED(
'Product'[EAN]
),
[Penetration]
)
)``````

Unfortuneately, I get the same value on every row of my visualisation using this measure:

4 REPLIES 4
Super User

@Anonymous In your example, where did the 1.4% come from for Prod2 for Incremental? Same question for the .2 for Prod3

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler
I'm kind of a rookie and realize that I obviously need to filter away users from my calculation in order to get the 'added contribution' for each product/row evaluated.

I have tried to incorporate this into my measure:

``````VAR _Rank = RANKX( ALLSELECTED( 'Product'[EAN] ) , CALCULATE( [Penetration] ) )
VAR _User = ALLSELECTED(User[UserId])
VAR _FilteredCalc = CALCULATE(
[Penetration],
FILTER(
'User',
NOT ( 'User'[UserId] ) IN _User
)
)

RETURN

CALCULATE(
[Penetration],
TOPN(
_Rank,
ALLSELECTED(
'Product'[EAN]
),
[Penetration]
)
)``````

But I will admit there is a decent chance I am trying to solve this in a nonsensical way unfortuneately.

This returns a blank value which I suspect is because my use of ALLSELECTED to select user to filter away is wrong

Anonymous
Not applicable

I essentially made it up. But it would be the remaining % Pen after filtering away purchases which overlaps each other (User buys both products). I hope this clears it up.

Super User

Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...