Forum Discussion
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
- Greg_DecklerCommunity Champion
Switch your "BeginWork" column to be "first" instead of "do not summarize"?
- AnonymousNot applicable
Greg_Deckler thanks.
I want to display both of the rows but show the measure only on the first row.
any way to do so?
- Greg_DecklerCommunity Champion
Anonymous - Can you share example/sample data? Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490