Forum Discussion
USE Relationship with Switch
- 1 year ago
David_Verdon , Try using this then
DAX
Sales Value =
VAR Status_ = SELECTEDVALUE(ProjectDetails[ProjectStatus])
VAR Rev = [Revenue Actual]
VAR Fee = SUM(ProjectDetails[FeeEstimate])
VAR Result =
SWITCH(
TRUE(),
Status_ = "Closed Project",
CALCULATE(
Rev,
USERELATIONSHIP(ProjectDetails[ClosedDate], 'Date'[Date])
),
Status_ = "Live Project",
CALCULATE(
Fee - Rev,
USERELATIONSHIP(CMap_ProjectDetails_Live[WonDate], 'Date'[Date]),
REMOVEFILTERS('Date'),
USERELATIONSHIP(ProjectDetails[ClosedDate], 'Date'[Date])
),
BLANK()
)
RETURN
ResultThe USERELATIONSHIP function for ClosedDate is explicitly deactivated for the "Live Project" calculation.
- 1 year ago
The problem is that variables in DAX aren't really variable, they are constants. Once they are evaluated they are never evaluated again, so trying to reevaluate them in a different context won't work. Try
Sales Value = VAR Status_ = SELECTEDVALUE ( ProjectDetails[ProjectStatus] ) VAR Result = SWITCH ( TRUE (), Status_ = "Closed Project", CALCULATE ( [Revenue Actual], USERELATIONSHIP ( ProjectDetails[ClosedDate], 'Date'[Date] ) ), Status_ = "Live Project", CALCULATE ( SUM ( ProjectDetails[FeeEstimate] ) - [Revenue Actual], USERELATIONSHIP ( CMap_ProjectDetails_Live[WonDate], 'Date'[Date] ) ), BLANK () ) RETURN Result
The problem is that variables in DAX aren't really variable, they are constants. Once they are evaluated they are never evaluated again, so trying to reevaluate them in a different context won't work. Try
Sales Value =
VAR Status_ =
SELECTEDVALUE ( ProjectDetails[ProjectStatus] )
VAR Result =
SWITCH (
TRUE (),
Status_ = "Closed Project",
CALCULATE (
[Revenue Actual],
USERELATIONSHIP ( ProjectDetails[ClosedDate], 'Date'[Date] )
),
Status_ = "Live Project",
CALCULATE (
SUM ( ProjectDetails[FeeEstimate] ) - [Revenue Actual],
USERELATIONSHIP ( CMap_ProjectDetails_Live[WonDate], 'Date'[Date] )
),
BLANK ()
)
RETURN
Result