Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Need Help: Power BI filter with group by

Hi All,

 

I have an unique screnario which i am at wits end trying to resolve. The data looks like below, where each user has number of hours worked for a week. The hours can have any value greater than 0.

usernamehoursstart weekend week
A407/4/20217/10/2021
A367/11/20217/17/2021
A347/18/20217/24/2021
A307/25/20218/1/2021
B507/4/20217/10/2021
B207/11/20217/17/2021
B207/18/20217/24/2021
B207/25/20218/1/2021
C287/4/20217/10/2021
C327/11/20217/17/2021
C447/18/20217/24/2021
C507/25/20218/1/2021

 

I want to add a dropdown to the visual where the user can select a value for number of hours(5,10,20, 30,35 etc).

If the latest hour value(based on dates) is greater than the value selected, ignore that user.

If the latest hour value(based on dates) is less than value selected, select user and get end date of period where its higher. 

For e.g. if the user selects 35, the output will be :

 end of week
A7/17/2021
B7/10/2021

In the above, 

A367/11/20217/17/2021

 row is higher than the 35 hour, so select that row and not the row above.

For B, a similar logic applies.

 

Please let me know if you have any ideas how to proceed with this. Thanks in advance.

  • Here is a measure expression that works with your username column in a  table visual, and a disconnected table with GENERATESERIES for the slicer.with

     

    SlicerHours = GENERATESERIES(20,50,5)
     

     

    Latest Week Over Limit =
    VAR slicervalue =
        MAX ( SlicerHours[Value] )
    VAR latesthours =
        LASTNONBLANKVALUE ( Hours[end week], CALCULATE ( MAX ( Hours[hours] ) ) )
    VAR latestweekabove =
        CALCULATE ( MAX ( Hours[end week] ), Hours[hours] >= slicervalue )
    RETURN
        IF ( latesthours >= slicervalueBLANK ()latestweekabove )

     

    Pat

     

2 Replies

  • mahoneypat's avatar
    mahoneypat
    Icon for Microsoft Employee rankMicrosoft Employee

    Here is a measure expression that works with your username column in a  table visual, and a disconnected table with GENERATESERIES for the slicer.with

     

    SlicerHours = GENERATESERIES(20,50,5)
     

     

    Latest Week Over Limit =
    VAR slicervalue =
        MAX ( SlicerHours[Value] )
    VAR latesthours =
        LASTNONBLANKVALUE ( Hours[end week], CALCULATE ( MAX ( Hours[hours] ) ) )
    VAR latestweekabove =
        CALCULATE ( MAX ( Hours[end week] ), Hours[hours] >= slicervalue )
    RETURN
        IF ( latesthours >= slicervalueBLANK ()latestweekabove )

     

    Pat

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Your are awesome! Much appreciated.