Measure for cumulative value doesn't work unless column is in the visual

gazpage

Active Member
Joined
Apr 17, 2015
Messages
393
Hi,

I have a data model with a fact table and a dimension table (SampleOrder). The Dimension Table looks like this:

[TABLE="width: 250"]
<tbody>[TR]
[TD]Sample[/TD]
[TD]Order[/TD]
[/TR]
[TR]
[TD]Top[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Middle[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]Bottom[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]Other[/TD]
[TD]4[/TD]
[/TR]
</tbody>[/TABLE]

The Sample Column is the relationship key back to the Fact table.

I want to create a simple table that shows the cumulative % of value represented by the Samples. The measure below works fine if I put the Order column in the visual, but if I drop it out and instead put the Sample column in then it just shows the actual percentage value and not the cumulative value. I can't really understand why this is happening.

I want to do a cumulative total of [Bank Value] (a simple SUM of the [Value] column

Code:
Bank Value Cum% (by sample) = 
DIVIDE ( 
 CALCULATE (
  [Bank Value],
  FILTER (
   ALL ( SampleOrder[Order] ),
   SampleOrder[Order] <= MAX ( SampleOrder[Order] )
  )
 ),
 CALCULATE (
  [Bank Value],
  ALLSELECTED()
 )
)

Thanks
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
You don't change the formula when you change from 'Order' to 'Sample' on rows? Filters are column specific. Your formula only manipulates the filters on 'SampleOrder[Order]', specifically 'ALL SampleOrder[Order]' returns the all values in the column, but has no effect on the SampleOrder[Sample] column now on the rows.
 
Upvote 0
Ah, right. So even though there is a one to one correspondence between Order and Sample if Order is not in the visual it has no filters? So the All actually isn't doing anything.
I need to put Sample in the ALL.

Thanks!
 
Upvote 0
Yes. Tables are actually a grouping of independent columns and a filter on one has no direct impact on another until after the filter context is generated and applied to model. So if Orders is not in one (or more) of the rows/columns/filter area/slicer or explicitly added as a setfilter argument to CALCULATE, there is no filter on SampleOrder[Order] column; there is only a filter on SampleOrder[Sample] (except for grand totals of course).
 
Upvote 0
Really helpful. One more question if I may.

I often find myself wanting to do an average by day product category. In order to iterate over a list of products, rather than every row in a table, I would have done something like:

Code:
AVERAGEX(
    ALL ( Table[Product] ),
    [Measure]
)

I thought this would iterate over all of the unique values in the Product column. Do I now understand correctly that any filters on other columns remain in place? So if I want to ensure I am iterating every item then I probably need to put the ALL in a CALCULATETABLE with an ALL (Table) in the filter or something?
 
Upvote 0
Yes, other filters do remain in place and may impact the results. 'ALL ( Table[Product] )' does return a single column table with all the unique values of 'Product'; but the list is still cross filtered by other columns. If you had, say, Table[Product Color] selected in a slicer for just a few colors, Table[Product] values will be cross filtered down to the values that meet the Table[Product Color] choices and therefore AVERAGEX only iterates over the now smaller set of values which presumably will result in a different measure result. If you were to put both Product and 'Product Color' on rows the calculation really stands out. You'll see the groups of 'Product' averaged by 'Product Color' if you don't change your original measure (All products with same Color have same measure result).
Getting the results you want does depend on understanding filter context. In general for performance reasons you are better off iterating over a single column. But if you need to remove the filters on other columns you may need to do 'All ( Table )'. It depends on situation.
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top