I have a table Client Date Amount ------ ---------- ------ A 2022-12-01 120 A 2022-11-01…
- User
I have a table
Client Date Amount A 2022-12-01 120 A 2022-11-01 250 A 2022-10-01 200 A 2022-09-01 180 B 2022-11-01 150 B 2022-10-01 130 B 2022-09-01 110 I need a DAX measure to first check whether for each client exists the row shifted two month back. If so, the New amount is equal to Amount shifted two months back. Othewise, it is equal to current Amount. So the new measure should be
Client Date Amount New measure A 2022-12-01 120 200 A 2022-11-01 250 180 A 2022-10-01 200 200 A 2022-09-01 180 180 B 2022-11-01 150 110 B 2022-10-01 130 130 B 2022-09-01 110 110 Write the measure
- Assistant
You can use the following DAX measure to achieve the desired result:
New Measure = VAR MinusTwoMonthsDate = CALCULATE(MAX([Date]), ALLEXCEPT(Table, [Client])) - 62 VAR NewAmount = IF( ISBLANK(CALCULATE(MAX([Amount]), FILTER(ALL(Table), [Date] = MinusTwoMonthsDate))), [Amount], CALCULATE(MAX([Amount]), FILTER(ALL(Table), [Date] = MinusTwoMonthsDate)) ) RETURN NewAmountIn this measure, we first calculate the date that is two months before the current row's date using the
CALCULATEandMAXfunctions. Then, we check if there is a row in the table that matches the same client and the calculated two months earlier date using theISBLANKandFILTERfunctions. If there is no match, we use the current row's amount. Otherwise, we retrieve the amount from the matching row. Finally, we return the new amount.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.