cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pintobean87
Frequent Visitor

Filter another measure so that negative numbers are not returned

Hello all,

 

I am using the following measure that basically rolls up 2 "week ending" periods for each employee, it adds together the "hours" in "week ending" to calculate overtime (measure subtracts 80 from total sum of hours for those two weeks to calculate overtime). The problem I'm having is that when I add the measure to a visual table I'm creating, it displays the total by including both negative and positive numbers. I only want the positive numbers since those are the overtime hours.

 

So, basically, I'm not sure how to filter out negative numbers so that the total is only made up of positive numbers (overtime).

 

Measure:

 

Measure = 
var _a = RANKX(ALLEXCEPT('Table','Table'[Employee]),[Week Ending],MAX('Table'[Week Ending]),ASC,Dense)
var _b = MAXX(FILTER(ALLEXCEPT('Table','Table'[Employee]),[Week Ending]<MAX('Table'[Week Ending])),[Week Ending])
var _c = CALCULATE(SUM('Table'[Hours]),FILTER(ALL('Table'),[Employee]=MAX('Table'[Employee])&&[Week Ending]<=MAX('Table'[Week Ending])&&[Week Ending]>=_b))-80
return IF(_a=ODD(_a),BLANK(),_c)

 

 

 

 

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @pintobean87 ,

 

Here is the sample data:

vjianbolimsft_0-1668740501420.png

 

Please try:

 

Measure = 
var _a = RANKX(ALLEXCEPT('Table','Table'[Employee]),[Week Ending],MAX('Table'[Week Ending]),ASC,Dense)
var _b = MAXX(FILTER(ALLEXCEPT('Table','Table'[Employee]),[Week Ending]<MAX('Table'[Week Ending])),[Week Ending])
var _c = CALCULATE(SUM('Table'[Hours]),FILTER(ALL('Table'),[Employee]=MAX('Table'[Employee])&&[Week Ending]<=MAX('Table'[Week Ending])&&[Week Ending]>=_b))-80
return IF(_a=ODD(_a)||_c<0,BLANK(),_c)

 

Output:

vjianbolimsft_1-1668740519680.png

 

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-jianboli-msft
Community Support
Community Support

Hi @pintobean87 ,

 

Here is the sample data:

vjianbolimsft_0-1668740501420.png

 

Please try:

 

Measure = 
var _a = RANKX(ALLEXCEPT('Table','Table'[Employee]),[Week Ending],MAX('Table'[Week Ending]),ASC,Dense)
var _b = MAXX(FILTER(ALLEXCEPT('Table','Table'[Employee]),[Week Ending]<MAX('Table'[Week Ending])),[Week Ending])
var _c = CALCULATE(SUM('Table'[Hours]),FILTER(ALL('Table'),[Employee]=MAX('Table'[Employee])&&[Week Ending]<=MAX('Table'[Week Ending])&&[Week Ending]>=_b))-80
return IF(_a=ODD(_a)||_c<0,BLANK(),_c)

 

Output:

vjianbolimsft_1-1668740519680.png

 

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Vote for T-Shirt Design

Power BI T-Shirt Design Challenge 2023

Vote for your favorite t-shirt design now through March 28.

March 2023 Update3

Power BI March 2023 Update

Find out more about the March 2023 update.

March Events 2023A

March 2023 Events

Find out more about the online and in person events happening in March!