Forum Discussion
DAX Measure with multiple conditions
Hi Roland74 ,
To create a DAX measure that satisfies the specified conditions, we first filter the data to include only rows where Posted = TRUE. For dates with multiple rows, we identify the row with the highest LineNumber using SUMMARIZE. To exclude months before the first posting date, we calculate the minimum posting date per project using CALCULATE with a MIN filter. Missing months are handled by propagating the latest valid value using a filter on dates up to the current month. For corrections, if CorrectionPosted = FALSE, the last valid value is propagated; if CorrectionPosted = TRUE and CorrectionDate is N/A, the value is propagated; otherwise, it stops after the correction date. Below is the combined DAX formula:
FinalMeasure =
VAR PostedData =
FILTER(
'DIM_ProjectPreclosure',
'DIM_ProjectPreclosure'[Posted] = TRUE
)
VAR MaxLinePerDate =
SUMMARIZE(
PostedData,
'DIM_ProjectPreclosure'[Date],
"MaxLineNumber", MAX('DIM_ProjectPreclosure'[LineNumber])
)
VAR FirstPostingDate =
CALCULATE(
MIN('DIM_ProjectPreclosure'[Date]),
FILTER(PostedData, 'DIM_ProjectPreclosure'[Posted] = TRUE)
)
VAR LastValue =
MAXX(
FILTER(
PostedData,
'DIM_ProjectPreclosure'[Date] <= MAX('Calendar'[Date])
),
'DIM_ProjectPreclosure'[Value]
)
VAR CorrectionLogic =
IF(
'DIM_ProjectPreclosure'[CorrectionPosted] = TRUE,
IF(
ISBLANK('DIM_ProjectPreclosure'[CorrectionDate]),
LastValue,
BLANK()
),
LastValue
)
RETURN
IF(
MAX('Calendar'[Date]) < FirstPostingDate,
BLANK(),
CorrectionLogic
)
This measure combines all conditions and ensures that the results dynamically adjust based on the selected month, following the rules for posting, corrections, and missing months.
Best regards,
- Roland741 year ago
Helper I
Hi DataNinja777,
Thanx for your solution. I didn't have time till now to check....
I don't have a date in the DIM_ProjectPreclosure, so it doesn't work.
I'll try to figure it out, you've put me in the right direction (i hope)