Forum Discussion
MAX Date returns blank for some rows (Calculated Column)
Hi,
I have a calculated column for which the goal is to search for the latest date when an item was purchased.
The DAX is as follows:
LatestPurchaseDateBeforeProduction
Hi CarlsBerg999 ,
For the filter function, its role is to get a table and return a table with the same columns as the original table, apply filter conditions row by row, and finally return the rows that meet the filter conditions.
Whereas CALCULATE creates a new filtering context and then counts the value expressions in the new context, not adding filters to the formula will lead to inconsistencies in the calculation logic.
1 = VAR ProductionDate = 'A'[Production Lot Completion] VAR MaterialID = 'A'[Material ID] VAR Latest = CALCULATE ( MAX ( 'GRIR'[Posting Date] ), 'GRIR'[Posting Date] <= ProductionDate, 'GRIR'[Material ID] = MaterialID ) RETURN Latest1 = VAR ProductionDate = 'A'[Production Lot Completion] VAR MaterialID = 'A'[Material ID] VAR Latest = CALCULATE ( MAX ( 'GRIR'[Posting Date] ), FILTER ( 'GRIR', ''[Posting Date] <= ProductionDate ), FILTER ( 'GRIR', 'GRIR'[Material ID] = MaterialID ) ) RETURN LatestYou can read related blog as below:
Specifying multiple filter conditions in CALCULATE - SQLBI
Best Regards,
Henry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 Replies
- AnonymousNot applicable
Hi try to put && instead of a coma after Production Date
- CarlsBerg999Helper V
Unfortunately this did not help my case.
- CarlsBerg999Helper VAdding Filters inside the calculate fixed the issue. Can anyone refer to guidance or explain why? I dont understand this.
CALCULATE (MAX ( 'GRIR Clearing Run Log'[Posting Date]),FILTER('GRIR Clearing Run Log','GRIR Clearing Run Log'[Posting Date]<= ProductionDate),FILTER('GRIR Clearing Run Log''GRIR Clearing Run Log'[Material ID]=MaterialID)) - v-henryk-mstfCommunity Support
Hi CarlsBerg999 ,
For the filter function, its role is to get a table and return a table with the same columns as the original table, apply filter conditions row by row, and finally return the rows that meet the filter conditions.
Whereas CALCULATE creates a new filtering context and then counts the value expressions in the new context, not adding filters to the formula will lead to inconsistencies in the calculation logic.
1 = VAR ProductionDate = 'A'[Production Lot Completion] VAR MaterialID = 'A'[Material ID] VAR Latest = CALCULATE ( MAX ( 'GRIR'[Posting Date] ), 'GRIR'[Posting Date] <= ProductionDate, 'GRIR'[Material ID] = MaterialID ) RETURN Latest1 = VAR ProductionDate = 'A'[Production Lot Completion] VAR MaterialID = 'A'[Material ID] VAR Latest = CALCULATE ( MAX ( 'GRIR'[Posting Date] ), FILTER ( 'GRIR', ''[Posting Date] <= ProductionDate ), FILTER ( 'GRIR', 'GRIR'[Material ID] = MaterialID ) ) RETURN LatestYou can read related blog as below:
Specifying multiple filter conditions in CALCULATE - SQLBI
Best Regards,
Henry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.