Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
viwinski7
Frequent Visitor

Need to Automatically Filter by Week and Time Range

Hello Power BI Community, 

 

My current client is asking if we could provide them a calculation in the form of a proportion below: 

 

# of clients discharged from Sunday-Sunday 5pm-5pm/ # of total clients served from Sunday-Sunday 5pm-5pm

 

We have two types of date/time columns: IntakeDate/Time and ExitDate/Time--my assumption is that we would use something based on the ExitDate/Time. 

 

Essentially, I need to calculate: 

1) a measure that can count the total amount of clients who were discharged in that date/time frame...and ALSO include the rest of the clients who don't have an exit date at all (that row would be blank within that date/time frame)

2) this measure has to be able to filter a specific week range AND time range

3) and if this could be coded/calculated in a way that can automatically update each week--that would be the gold standard. We are trying to not use interactive/slicers fields on the dashboards. (if possible) 

 

Thank you for anyone who is willing to help! 

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

Hi @viwinski7 ,  

You could modify the MaxArrival2 column by the following formula:

count =
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        ALL ( 'Table' ),
        [ExitDate/Time] = BLANK ()
            || (
                WEEKNUM ( [ExitDate/Time] ) = WEEKNUM ( TODAY () )
                    && (
                        (
                            WEEKDAY ( [ExitDate/Time], 2 ) = 6
                                && TIMEVALUE ( [ExitDate/Time] ) < TIMEVALUE ( "17:00:01" )
                        )
                            || (
                                WEEKDAY ( [ExitDate/Time], 2 ) = 7
                                    && TIMEVALUE ( [ExitDate/Time] ) >= TIMEVALUE ( "17:00:00" )
                            )
                            || ( WEEKDAY ( [ExitDate/Time], 2 ) IN { 1, 2, 3, 4, 5 } )
                    ))))

The final output is shown below:  

v-yalanwu-msft_0-1622712946134.png

Best Regards,
Community Support Team_ Yalan Wu
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

4 REPLIES 4
v-yalanwu-msft
Community Support
Community Support

Hi, @viwinski7 ;

Could you please tell me if your problem has been solved?

If it is, could you please mark the helpful replies as a solution to close this topic and help others can learn from it ?

 

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

v-yalanwu-msft
Community Support
Community Support

Hi @viwinski7 ,  

You could modify the MaxArrival2 column by the following formula:

count =
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        ALL ( 'Table' ),
        [ExitDate/Time] = BLANK ()
            || (
                WEEKNUM ( [ExitDate/Time] ) = WEEKNUM ( TODAY () )
                    && (
                        (
                            WEEKDAY ( [ExitDate/Time], 2 ) = 6
                                && TIMEVALUE ( [ExitDate/Time] ) < TIMEVALUE ( "17:00:01" )
                        )
                            || (
                                WEEKDAY ( [ExitDate/Time], 2 ) = 7
                                    && TIMEVALUE ( [ExitDate/Time] ) >= TIMEVALUE ( "17:00:00" )
                            )
                            || ( WEEKDAY ( [ExitDate/Time], 2 ) IN { 1, 2, 3, 4, 5 } )
                    ))))

The final output is shown below:  

v-yalanwu-msft_0-1622712946134.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.  

v-yalanwu-msft
Community Support
Community Support

Hi , @viwinski7 ,

 

I am not very clear about your question. Based on my understanding, I have created a simple example to calculate the total of discharged or blank on Sunday; if you want to update automatically, you can change WEEKNUM ( [ExitDate/Time] ) = 12 to  WEEKNUM ( [ExitDate/Time] ) = WEEKNUM ( TODAY());  as follows:

count =
COUNTROWS (
    FILTER (
        ALL ( 'Table' ),
        WEEKNUM ( [ExitDate/Time] ) = 12
            && (
                [ExitDate/Time] = BLANK ()
                    || WEEKDAY ( [ExitDate/Time], 2 ) = 7
                        && TIME ( HOUR ( [ExitDate/Time] ), MINUTE ( [ExitDate/Time] ), SECOND ( [ExitDate/Time] ) )
                            = TIME ( 17, 0, 0 )
            )
    )
)

The final output is shown below:

v-yalanwu-msft_0-1622429112536.png

If this is still not what you want, please provide me with more details about your table and
your problem or share me with your pbix file after removing sensitive data.

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Essentially, 

 

I need this: 

viwinski7_0-1622656235819.png

 

but in a way that I don't have to go in each week and update the advanced filter. 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.