VAR inside CALCULATE?

macfuller

Active Member
Joined
Apr 30, 2014
Messages
319
Office Version
  1. 365
Platform
  1. Windows
Hopefully others have encountered this situation.

There's a lot I need to wrap my head around in DAX and the order that calculations happen is one of them. I'm not sure whether the following measure is doing what I think it's doing without having to create multiple intermediate helper columns in a very large table.

I have 4 date events and I want to track each duration between them. The first event always has a date but the middle 2 events are optional and the last may be delayed.

Voucher Entry -> Voucher Match -> Voucher Approval -> Voucher Paid

The final objective is to generate a pivot table showing the average lag times for each step (where the event happened) to end as a stacked bar chart. So I will be able to tell how long each step of the voucher payment process takes based on whatever filter type I choose (e.g. by vendor).

This particular measure is supposed to tell me, if there is an Approval date, how long it happened after the latest prior event. In this case I'm expecting CompleteDate to be recalculated for every row of the filtered table within the AVERAGEX statement. Is it? The syntax doesn't generate an error, but as I say it's hard to tell without creating a bunch of helper columns if I'm getting the value I expect.

Code:
Avg Lag Approval Days :=CALCULATE (
    AVERAGEX (
        Vouchers,
        VAR CompleteDate =
            IF (
                ISBLANK ( Vouchers[Voucher Match Date] ),
                Vouchers[Voucher Entered Date],
                Vouchers[Voucher Match Date]
            )
        RETURN
            Vouchers[Voucher Approval Date] - CompleteDate
    ),
    FILTER (
        Vouchers,
        NOT (
            ISBLANK ( Vouchers[Voucher Approval Date] )
        )
    )
)
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi macfuller,

In this case I'm expecting CompleteDate to be recalculated for every row of the filtered table within the AVERAGEX statement. Is it?

yes CompleteDate is calculate for each row
 
Upvote 0
Solution

Forum statistics

Threads
1,224,822
Messages
6,181,165
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