Dynamic Measure + Prior Year Avg/Sum

SimonNU

Board Regular
Joined
Jul 11, 2013
Messages
140
The below is a dynamic measure (using a disconnected table) for measures [measure 1], [measure 2], [measure 3] ... [measure n] which is wrapped inside a prior year calculation.

Unfortunately, [measure 3] actually requires an AVERAGEX as opposed to SUMX. Can anyone think of an elegant way to re-arrange this to account for this adjustment?


Code:
[COLOR=#FFFFFF][FONT=Consolas]Dynamic PY CSC :=[/FONT][/COLOR]
Dynamic Measure - PY :=
IF (
    HASONEVALUE ( 'Dynamic Measures'[ID] ),
    SUMX (
        VALUES ( 'Time Filters'[YearPeriodNumber] ),
        CALCULATE (
            SWITCH (
                VALUES ( 'Dynamic Measures'[ID] ),
                1, [measure 1],
                2, [measure 2],
                3, [measure 3]
            ),
            ALL ( 'Time Filters' ),
            FILTER (
                ALL ( 'Time Filters'[YearPeriodNumber] ),
                'Time Filters'[YearPeriodNumber]
                    = EARLIER ( 'Time Filters'[YearPeriodNumber] ) - 12
            )
        )
    )
)
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hmm... so, this looks a bit weird to me. In that, I would expect you to have a [Dynamic Measure] already, and for this PY version to just "use" that.

=CALCULATE([Dynamic Measure], ALL( 'Time Filters' ), 'Time Filters'[YearPeriodNumber] = VALUES('Time Filters'[YearPeriodNumber]) - 12)

Or ... something like that. Am I cray cray?
 
Upvote 0
You're correct, [Dynamic Measure] exists and I do use it in the measure normally. I expanded it to show how SUMX negatively effects a dynamic measure that is an average (it sums up the averages for the selected periods - not good!). In hindsight I probably shouldn't have :)

I like your attempt as using calculate to solve the issue. Unfortunately it appears to only cater for scalar values - it bugged when I selected more than 1 period.

The actual formula is:
Code:
Dynamic PY Measure :=IF (
    HASONEVALUE ( 'Dynamic Measures'[ID] ),
    SUMX (
        VALUES ( 'Time Filters'[YearPeriodNumber] ),
        CALCULATE (
            [Dynamic Measure],
            ALL ( 'Time Filters' ),
            FILTER (
                ALL ( 'Time Filters'[YearPeriodNumber] ),
                'Time Filters'[YearPeriodNumber]
                    = EARLIER ( 'Time Filters'[YearPeriodNumber] ) - 12
            )
        )
    )
)
 
Upvote 0
I think I am getting thrown off by weird measure naming or something, I will try and ignore that... and just read your words :-P

So... you have a situation where sometimes you want a SUMX and sometimes you want an AVERAGEX. I have a ... niggle... in the back of my head. AVERAGEX is secretly SUMX/COUNTROWS() maybe? Can we always SUMX, but based on the measure selected... sometimes divide by the countrows? Like... divide by COUNTROWS(Table) - [Zero or One from Measure Selected] * COUNTROWS(Table) ... so that you divide by COUNTROWS()-COUNTROWS() or... 1, or you divide by COUNTROWS()-0*COUNTROWS() ... which gives the AVERAGE?

I dunno, its 11:30pm after a long day of DAX and C#, I'm hoping my niggle of an idea gives you an actual idea...? :)
 
Upvote 0

Forum statistics

Threads
1,225,420
Messages
6,184,879
Members
453,264
Latest member
AdriLand

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