Forum Discussion
Total in table visualization not being calculated when it depends on row date
- Anonymous1 year ago
Hi jasonyeung87 ,
Thank you for reaching out to the Microsoft Fabric Community. Also thankyou pankajnamekar25 for your input.
you're correct, the issue occurs because the Total row lacks row context, so the original measure sums vacation hours across the entire dataset instead of the visible date range.
To fix this, here's a revised measure that:
- Calculates vacation per week as before and dynamically uses the min and max visible dates for the Total row.
Vacation Hours (with Correct Total) := VAR IsTotal = NOT HASONEVALUE('Timesheet'[Timesheet ID]) VAR StartDate = MIN('Timesheet'[Week Start Date]) VAR EndDate = MAX('Timesheet'[Week End Date]) RETURN IF ( IsTotal, CALCULATE( SUM('Time-Off Split'[Krow__Hours__c]), 'Time-Off Split'[Krow__Date__c] >= StartDate, 'Time-Off Split'[Krow__Date__c] <= EndDate, RELATED('Time Off'[Krow__Type__c]) = "Vacation", 'Time-Off Split'[IsDeleted] = FALSE() ), CALCULATE( SUM('Time-Off Split'[Krow__Hours__c]), FILTER ( 'Time-Off Split', 'Time-Off Split'[Krow__Date__c] >= SELECTEDVALUE('Timesheet'[Week Start Date]) && 'Time-Off Split'[Krow__Date__c] <= SELECTEDVALUE('Timesheet'[Week End Date]) && RELATED('Time Off'[Krow__Type__c]) = "Vacation" && 'Time-Off Split'[IsDeleted] = FALSE() ) ) )This should now reflect correct totals based only on the weeks shown in your table.
Hope this helps. Please reach out for further assistance.
If this post helps, then please consider to Accept as the solution to help the other members find it more quickly and a kudos would be appreciated.
Thank you.
Hello jasonyeung87
Try this measure
Vacation Hours (with Total) =
SUMX (
VALUES('Timesheet'[Timesheet ID]), // Replace with a unique key per row
VAR StartDate = CALCULATE(SELECTEDVALUE('Timesheet'[Week Start Date]))
VAR EndDate = CALCULATE(SELECTEDVALUE('Timesheet'[Week End Date]))
RETURN
CALCULATE (
SUM('Time-Off Split'[Krow__Hours__c]),
FILTER (
'Time-Off Split',
'Time-Off Split'[Krow__Date__c] >= StartDate &&
'Time-Off Split'[Krow__Date__c] <= EndDate &&
RELATED('Time Off'[Krow__Type__c]) = "Vacation" &&
'Time-Off Split'[IsDeleted] = FALSE()
)
)
)
Thanks,
Pankaj Namekar | LinkedIn
If this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.
Hi pankajnamekar25 ,
Thanks for your suggestion on the measure. I tried the measure, but it didn't work for me. The result was:
The vacation hours didn't look correct. There was a total generated, but it looks like it was totalling up the vacation hours of all dates. To debug, I created the following measure:
Debug Selected Values =
"WeekStart: " & FORMAT(SELECTEDVALUE('Timesheet'[Week Start Date]), "yyyy-mm-dd") &
", WeekEnd: " & FORMAT(SELECTEDVALUE('Timesheet'[Week End Date]), "yyyy-mm-dd")
And added it to the column. It appears on the right column in above screenshot. It is displaying the start and end dates for each row, but there are no dates for the total row. I wanted the vacation total to be from the start date of the first row and the end date of the last row.
Sincerely,
Jason