问题
I am trying to select the record with the latest date, all of the records in the database have these basic columns AssetNumber, WorkOrderNumber, ScheduledEndDate, Department
I want to find all the latest work order "date" for each asset in a specific department. I have a basic measure and column to do this but it is not working.
How do I filter the records and then apply the max date function. I have tried using ALL, ALLEXCEPT, ALLSELECTED etc.
| ASSET | DEPARTMENT | WOSCHED_ENDDATE |
|-------|------------|-----------------|
| 2160 | 57257E | 11/29/2011 |
| 2160 | 57257E | 7/28/2014 |
| 6440 | 57257E | 3/5/2012 |
| 6440 | 57257E | 3/9/2015 |
At the basic level I need to remove the two records with the old dates from my visual. I can find the most recent (MAX) date of the entire column but I cannot get the MAX function to work in the context of the filtered values which by department like I have in the sample grid.
Thank you
回答1:
Try creating a measure:
MaxDate =
CALCULATE (
MAX ( 'Data_Mart'[WOSCHED_ENDDATE] ),
ALLSELECTED ( 'Data_Mart'[WOSCHED_ENDDATE] )
)
I think the simple:
MaxDate = MAX( 'Data_Mart'[WOSCHED_ENDDATE] )
should work.
In Power BI using a matrix I get:
Note WOSCHED_ENDDATE
is not included in the matrix if you include it the measure will be evaluated per each row so the MaxDate measure will give the same date in each row.
Let me know if this helps.
来源:https://stackoverflow.com/questions/40514584/how-to-i-use-the-max-function-in-power-bi-only-on-the-filtered-records