USERELATIONSHIP filter question

macfuller

Active Member
Joined
Apr 30, 2014
Messages
319
Office Version
  1. 365
Platform
  1. Windows
I've got a measure where I'd like to have a USERELATIONSHIP clause in the CALCULATE. The code below works... however, I'm not clear why I can't add the USERELATIONSHIP as a filter parameter to the "inner" CALCULATE. If I do that without the outer CALCULATE the measure returns blank<blank>.
Code:
Discount Taken Total :=CALCULATE (
    CALCULATE (
        SUM ( Vouchers[Discount Amount] ),
        FILTER (
            Vouchers,
            NOT (
                ISBLANK ( Vouchers[Discount Due Date] )
            )
                && NOT (
                    ISBLANK ( Vouchers[Payment Date] )
                )
                && Vouchers[Discount Due Date] >= Vouchers[Payment Date]
        )
    ),
    USERELATIONSHIP ( Vouchers[Payment Date], 'AP Calendar'[Date] )
)
The AP Calendar table is a standard date table - the default relationship is to the Voucher Entered Date, but as I'm tracking discount payments I need to group my spend as of the payment date.
In order to receive a discount (e.g. 2% 10 days) we must pay prior to or on the discount due date.
The Payment Date is blank if vouchers have not been paid.
The Discount Date is blank if we do not offer a discount for that vendor.</blank>
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
You measure works because the table Vouchers, on which you are iterating using FILTER, is calculated within the context of the relationship between Vouchers[Payment Date] and 'AP Calendar'[Date], and not in the context of the active relationship.
On the other hand, if you use USERELATIONSHIP inside the inner calculate, then the table Vouchers, on which you are iterating using FILTER, is calculated in the context of the active relationship and the intersection between the result of FILTER and USERELATIONSHIP does not return anything in your case.
 
Upvote 0
The FILTER should return records that have a Payment date since I'm looking for non-blank values. So I would think there should be an intersection as the calendar table has 3 years of values thru Dec 2019 (for projected measures)? Does the order of the relationship parameters in USERELATIONSHIP matter?
 
Upvote 0
Normally as first argument you would use the column from the many side and as second argument the column from the one side. But if you place them incorrectly I believe DAX will correct them for you
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

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