Forum Discussion

average_joe's avatar
average_joe
Frequent Visitor
3 years ago

DAX Help - Calculate min excluding weeekends

I have created a report which shows the number of staff visiting each office by day.  The report page has a filter applied where 'dayofweek' is not 'Sat' or 'Sun'.  Users can select a date range and office locations for which to view office attendance.

 

I have customised some DAX I found in the forums here to give me a calculation of the lowest office attendance for the selected date range and offices.  I have incorporated the filter that is applied to the report page ('dayofweek' is not 'Sat' or 'Sun') but wanted to see if there is a better way to do this. For example, if I allowed users to select the 'dayofweek', is there a way I can change the below DAX so that this calculation is updated without me having to manually change the IN portion of the statement?

 

I've tried playing around with the ALLSELECTED part of the formula but don't understand a lot of the DAX so haven't had much luck.

 

The DAX I've used is below.

 

VAR MinDate = CALCULATE(MIN('Date'[Date]), ALLSELECTED('Date'[Date]))

VAR MaxDate = CALCULATE(MIN('Date'[Date]), ALLSELECTED('Date'[Date]))

VAR Period = FILTER(DATESBETWEEN('Date'[Date], MinDate, MaxDate), NOT(WEEKDAY('Date'[Date],2) IN {6,7}))

 

RETURN

CALCULATE(

    MINX(

        VALUES('Date'[Date]),

        [Unique_number_of_staff]

    ),

    Period

)

 

 

1 Reply

  • v-zhangti's avatar
    v-zhangti
    Icon for Community Support rankCommunity Support

    Hi, average_joe 

     

    Can you provide sample data for testing? Sensitive information can be removed in advance. What kind of expected results do you expect? You can also show it with pictures or Excel. I look forward to your response.

     

    Best Regards,

    Community Support Team _Charlotte

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