Forum Discussion
ajitsahoo8338
Helper III
1 year agoI need help with this logic
Hello Everyone. I need help with this logic. this is my sample data- Project Name Activity Number Task_Name Resource Date Recorded_Hours EndDate TGX 3118.1 WP03 Maintenance MECHANICA...
- 1 year ago
Please try these calc columns
Last Date = VAR _LastDate = MAXX ( FILTER ( 'Table', 'Table'[Project Name] = EARLIER ( 'Table'[Project Name] ) && 'Table'[Activity Number] = EARLIER ( 'Table'[Activity Number] ) && 'Table'[Task_Name] = EARLIER ( 'Table'[Task_Name] ) && 'Table'[Resource] = EARLIER ( 'Table'[Resource] ) && 'Table'[Recorded_Hours] > 0 ), [Date] ) RETURN COALESCE ( _LastDate, 'Table'[EndDate] ) Total Recorded Hours = SUMX ( FILTER ( 'Table', 'Table'[Project Name] = EARLIER ( 'Table'[Project Name] ) && 'Table'[Activity Number] = EARLIER ( 'Table'[Activity Number] ) && 'Table'[Task_Name] = EARLIER ( 'Table'[Task_Name] ) && 'Table'[Resource] = EARLIER ( 'Table'[Resource] ) && 'Table'[Recorded_Hours] > 0 ), [Recorded_Hours] )
VahidDM
Super User
1 year ago
Create a calculated column that checks each combination, sums their recorded hours, and returns the appropriate date. For example:
Result Date =
VAR CurrentProject = 'Table'[Project Name]
VAR CurrentActivity = 'Table'[Activity Number]
VAR CurrentTask = 'Table'[Task_Name]
VAR CurrentResource = 'Table'[Resource]
VAR TotalHours =
CALCULATE(
SUM('Table'[Recorded_Hours]),
FILTER(
ALL('Table'),
'Table'[Project Name] = CurrentProject &&
'Table'[Activity Number] = CurrentActivity &&
'Table'[Task_Name] = CurrentTask &&
'Table'[Resource] = CurrentResource
)
)
VAR LastHourDate =
CALCULATE(
MAXX(
FILTER(
ALL('Table'),
'Table'[Project Name] = CurrentProject &&
'Table'[Activity Number] = CurrentActivity &&
'Table'[Task_Name] = CurrentTask &&
'Table'[Resource] = CurrentResource &&
'Table'[Recorded_Hours] > 0
),
'Table'[Date]
)
)
RETURN
IF(
TotalHours > 0,
LastHourDate,
'Table'[EndDate]
)
This column returns the last date with recorded hours if any exist, otherwise it returns the EndDate for that combination.
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
ajitsahoo8338
Helper III
1 year agoHello VahidDM Thank you for response. Your DAX is not giving the correct output for some. For this below, it is showing the wrong date.
| Project Name | Activity Number | Resource | Task_Name | Date | Recorded_Hours | EndDate | Result Date |
| RGS27 MRS | 3053.1 | MECHANICAL | GC Options Group | 10/10/2024 0:00 | 0 | 10/11/2024 0:00 | 12/3/2024 0:00 |
| RGS27 MRS | 3053.1 | MECHANICAL | GC Options Group | 10/11/2024 0:00 | 0 | 10/11/2024 0:00 | 12/3/2024 0:00 |