We use this to filter to find volunteers based on their Scheduling Preferences. They do not have to be scheduled. Volunteers must however be apart of a scheduling group and have scheduling preferences set on their profile.

I have attached screenshots of these instructions as well for a general idea of what is happening.

You will need these blocks: Page Parameter Filter  Dynamic Data

Of course, adjust this code to meet your instance. 

Page Parameter Filter Block Configuration:

    Add the Groups, Schedules, and Location filters. There is SQL inserted into the Values of the Groups and Locations. 

    Groups: Field Type = Multi-Select, Key = Groups;  Insert this code for the Values of the Multi-Select.

Select 
	Concat(G.Name,' - ',C.Name) As [Text]
	, G.Id As [Value]
From [Group] G
Left Join Campus C On C.Id = G.CampusId
Where G.GroupTypeId = *Your Scheduling Group Type Here*
And G.IsActive = 1
And G.IsArchived = 0
Order By G.Name
    


    Schedules: Field Type = Schedules, Key = Schedules; No code to add to this.


    Locations: Field Type = Multi-Select, Key = Locations;  Insert this code for the Values of the Multi-Select. 

Select 
	L.Id As [Value]
	, Case When PL.Id is not null then Concat(L.[Name],' - ',PL.[Name]) Else L.[Name] End As [Text] 
From [Location] L
Left Join [Location] PL On PL.Id = L.ParentLocationId
Where L.[Name] is not null
And L.[Name] != ''
Order By L.Id


Dynamic Data Block Configuration:

    Insert this code into the block. It is a Person report and there are no additional settings set on the block. 




{% assign schedule = PageParameter.Schedules | Split:',' %}
{% assign scheduleFirst = schedule | First %}
{% assign location = PageParameter.Location %}
{% assign groups = PageParameter.Groups  %}
{% assign locations = PageParameter.Locations %}

{% if groups != null and groups != empty %}
    Select 
    	P.Id
    	, Concat(P.FirstName,' ',P.LastName) As [Name]
    	, G.Name As [Group Name]
    	, STRING_AGG(S.Name, ', ') As [Schedule]
    	, STRING_AGG(L.Name, ', ') As [Location]
    From GroupMember GM
    Inner Join [Group] G On G.Id = GM.GroupId
    Inner Join Person P On P.Id = GM.PersonId
    Inner Join GroupMemberAssignment GMA On GMA.GroupMemberId = GM.Id
    Inner Join Schedule S On GMA.ScheduleId = S.Id
    Inner Join [Location] L On GMA.LocationId = L.Id
    Where G.Id In ({{groups}})
    {% if scheduleFirst != null %}
        And(
        {% for item in schedule %}
            {% if forloop.first %}
            (Cast(S.Guid As nvarchar(max)) = '{{item | SanitizeSql}}')
            {% else %}
            Or (Cast(S.Guid As nvarchar(max)) = '{{item | SanitizeSql}}')
            {% endif %}
        {% endfor %}
        )
    {% endif %}
    {% if location != null and location != empty %}
    And L.Guid = '{{location}}'
    {% endif %}
    {% if locations != null and locations != empty %}
    And L.Id In ({{locations}})
    {% endif %}
    
    Group By P.Id, P.FirstName, P.LastName, G.Name
    
    Order By P.LastName
    
{% endif %}