Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

MAKE SUM() IGNORE ROW CONTEXT

Hi,

 

I am trying to create a measure that will calculate the sum of another calculation that converts from seconds to hours that runs per row in "activity" table and returns the total of the sum if it's the "Total".

 

problem is, that a date can appear more than once to the same employee and i would like to get the sum per date and emp_no redgardless the fact that same date and emp_no appears more than once in a table visual.

 

this is the code i'm using for that measure "HoursTotal", "Table1" is for the total and "Table2" is for the row.

HoursTotal = 

VAR Table1 = SUMMARIZE(FILTER(ALLSELECTED(activity),activity[Date] = activity[Date] && activity[Emp_no]=activity[Emp_no]),
                    activity[Date],activity[Emp_no],"HoursTotal",DIVIDE(SUM(activity[S_Total]),3600,0))

VAR Table2 = GROUPBY(activity,activity[Date],activity[Emp_no],"Day Hours",SUMX(CURRENTGROUP(),activity[S_Total]/3600))

VAR HoursDay = CALCULATE(SUMX((FILTER(Table2,activity[Date] = activity[Date] && activity[Emp_no]=activity[Emp_no])),[Day Hours]))

VAR Total = SUMX(Table1,[HoursTotal])

RETURN IF(HASONEFILTER(activity[Date]),HoursDay,Total)

 

Here is the table visual

 

the visual is filtered to show only a certain emp_no and september 2019.

 

for the date of the 20/09/2018 the measure should show 13.62 instead of what is currently shown.

 

Please help me solve this issue.

 

thanks!

  • Anonymous - Well it is doing a SUMMARIZE so that can take some time, See if this speeds it up:

     

    Measure 3 = 
    VAR __date = MAX([Date])
    VAR __table = SUMMARIZE(FILTER(ALL('Table4'),[Date]=__date),[Emp_no],[Date],"__hours",SUM([S_Total])/60/60)
    RETURN
    MAXX(__table,[__hours])

    As for the 2nd one, that should be equivalent. I created a second measure just like it and got the same results so not sure what is going on there. See attached, Table4, Page 3.

8 Replies