Search code examples
parametersdax

Count of rows that are indirectly related


I have a powerbi report using data about zoom meetings in my organization. I have an org table with all of our employeees, linked to my fact table (zoom attendance) via a bridge table (Email to MMID Link) and two inactive relationships. The fact table has a row for every attendee of every meeting with details about the attendee and the host. It is setup this way because an employee may have multiple email addresses, so bridge table enables the many to many relationship, the two inactive relationships are because an employee may be the meeting host or the meeting attendee. The Zoom meetings table is a compromise solution I used to solve a similar problem previously that has some aggregate data about the meetings and has a single row per meeting instance (uuid).

relevant portion of semantic model

I am using calculation groups to allow the report user to dynamically select if they want to view metrics about an employee or department's hosted meetings, attended meetings, or all meetings they participated in. I am also using a field parameter to present several measures in a single table. My setup works fine for the other measures I have for meeting counts and durations, but I am having trouble logic-ing a solve for Attendee counts.

filters applied to the table

Basically, the issue is that if the Zoom Attendees value is selected for "Selected users are" (which applies the calculation using the relationship between the employee and the meeting attendee field) then a count of rows in the Zoom Attendance table only counts themselves and won't count everyone else that attended the same meetings. I feel like there is a fairly simple solution to get what I'm looking for but for some reason my brain just isn't clicking.

Some more details: DAX Code for the Calculation items that select relationship to use:

Zoom Hosts = CALCULATE (
    SELECTEDMEASURE (),
    USERELATIONSHIP ( 'Zoom Attendance'[HostEmail], 'Email to MMID Link'[Primary Email] )
)
Zoom Attendees = CALCULATE (
    SELECTEDMEASURE (),
    USERELATIONSHIP ( 'Zoom Attendance'[AttendeeEmail], 'Email to MMID Link'[Primary Email] )
)
All Zoom Participation = VAR att =
    CALCULATE (
        SELECTEDMEASURE (),
        USERELATIONSHIP ( 'Zoom Attendance'[AttendeeEmail], 'Email to MMID Link'[Primary Email] )
    )
VAR host =
    CALCULATE (
        SELECTEDMEASURE (),
        USERELATIONSHIP ( 'Zoom Attendance'[HostEmail], 'Email to MMID Link'[Primary Email] )
    )
RETURN
    att + host

TLDR I need to create a measure that count all rows in the zoom attendance table that have a uuid that matches to a selected employee, but I can't specify the relationship to use or which column, host or attendee, the employee is listed in. I have tried using the Zoom Meetings table to create a filtered list of UUIDs and then filter matching rows from the zoom attendance table but am doing something wrong. I was honestly hoping spelling this out would get me to think of the solution, but no dice.

TLDR I need to create a measure that count all rows in the zoom attendance table that have a uuid that matches to a selected employee, but I can't specify the relationship to use or which column, host or attendee, the employee is listed in. I have tried using the Zoom Meetings table to create a filtered list of UUIDs and then filter matching rows from the zoom attendance table but am doing something wrong. I was honestly hoping spelling this out would get me to think of the solution, but no dice. I was trying something like this:

Attendees in Zoom Meetings = 
VAR uuids = ADDCOLUMNS('Zoom Meetings', "validuuid", 'Zoom Meetings'[UUID])
VAR filtered = FILTER('Zoom Attendance', 'Zoom Attendance'[UUID] IN uuids)
RETURN
COUNTROWS(filtered)

Solution

  • Same Nseir got me thinking in the right direction, what I ended up with is:

    Attendees in Zoom Meetings = 
    VAR user = SELECTEDVALUE( 'Email to MMID Link'[Primary Email] )
    VAR attend =
        COUNTROWS(
            CALCULATETABLE(
                'Zoom Attendance',
                ALL( 'Zoom Attendance' ),
                CALCULATETABLE(
                    DISTINCT( 'Zoom Attendance'[UUID] ),
                    CONTAINSSTRING( 'Zoom Attendance'[AttendeeEmail], user ),
                    'Zoom Attendance'[is_host] = 0
                ),
                'Zoom Attendance'[AttendeeEmail] <> user
            )
        )
    VAR host =
        COUNTROWS(
            CALCULATETABLE(
                'Zoom Attendance',
                CALCULATETABLE(
                    DISTINCT( 'Zoom Attendance'[UUID] ),
                    CONTAINSSTRING( 'Zoom Attendance'[HostEmail], user )
                ),
                'Zoom Attendance'[is_host] = 0
            )
        )
    VAR _select =
        SWITCH(
            SELECTEDVALUE( 'Use Relationship'[User Type] ),
            "Zoom Hosts", host,
            "Zoom Attendees", attend,
            "All Zoom Participants", host + attend,
            0
        )
    RETURN
        _select
    

    this gives the correct value when looking at a single employee, for aggregation I think I'm just going to accept a slightly lesser solution and use the meeting table to create a meeting attendee count for each meeting and just sum that.