Forum Discussion

cwollett's avatar
cwollett
Advocate II
1 year ago
Solved

Data model for Survey data

I work at a school that does class evaluations at the end of each term. I am trying to figure out how best to model and analyze this data and am having some issues with what I thought would be a removefilters measure. This will be a little involved, but hopefully you stick with me.

 

Data model - Dummy data

Class table with information about each class, something like:

class_idclass_namedepartment
1PSY 101 - General Psychologypsychology
2PSY 111 - Statistical Reasoningpsychology
3MATH 120 - College Algebramathematics

Instructor table like:

instructor_idinstructor_name
1John Smith
2Jane Doe
3Bob Smith

Question table, like (note that question type is important for classes with more than one instructor as course questions are asked once while the instructor questions are asked per instructor):

question_idquestionquestion_type
1Instructions were clearInstructor
2Activites were purposefulCourse
3This course challenged meCourse

Fact table sample row:

class_idinstructor_idstudent_idquestion_idresponseresponse_text
11115Strongly Agree

 

Needs/DAX Help

I want to make a visual that displays the average for an instructor compared to the average for their department.

For course-based questions, my instructor average measure is:

 

 

COURSE MEAN = 
var _responses =
# --summarizing since you do not need instructor id for course-related questions
CALCULATETABLE(
    SUMMARIZE( 
        'Fact Table'[COURSE_ID],
        'Fact Table'[QUESTION_ID],
        'Fact Table'[STUDENT_ID],
        'Fact Table'[RESPONSE]
    ),
    'Dim Questions'[QUESTION_TYPE] = "COURSE"
)
RETURN
    AVERAGEX(_responses, [RESPONSE])

 

 

 

What DAX would I need to then make something that would go in a matrix to display the above value side-by-side with the department value? I tried using the following, but it gives me the same value for both measures:

 

 

DEPARTMENT MEAN = 
var _responses =
# --summarizing since you do not need instructor id for course-related questions
CALCULATETABLE(
    SUMMARIZE( 
        'Dim Courses'[DEPARTMENT],
        'Fact Table'[QUESTION_ID],
        'Fact Table'[STUDENT_ID],
        'Fact Table'[RESPONSE]
    ),
    'Dim Questions'[QUESTION_TYPE] = "COURSE"
)
RETURN
    AVERAGEX(_responses, [RESPONSE])

 

 

If it matters, there will eventually be row-level security on the data model so that instructors only see their information. Does that mean I'm going to have to make another dimension table of data summarized per department so that it doesn't get filtered by course/instructor?

 

I would like to use this measure in more than one place, if possible. The most involved place would be a matrix that will likely include:

  • Question
  • Instructor Name
  • Class Name

I tried to do this with a calculate including remove filters (question_id, class_id) but that did not work out.

  • cwollett's avatar
    cwollett
    1 year ago

    Unfortunately the ALLSELECTED option will not work because we will have row level security on the dataset, so the RLS will act as an additional filter. The only way I have found to work around the RLS issue is to create an unrelated summarized table.

6 Replies

  • AllisonKennedy's avatar
    AllisonKennedy
    Community Champion

    cwollett thanks for all the detail in your question.

     

    What fields are you wanting / trying to use in your matrix? You need to consider that every field you put in the matrix adds a filter context to your measure calculation / result. So if you want a Departmental average, you need to clear all other filters coming from your matrix visual within the DAX measure itself.

     

    Measure functions such as ALLSELECTED and ALLEXCEPT will be helpful for you here. Have you used those before?

    • cwollett's avatar
      cwollett
      Advocate II

      Thanks for the response, AllisonKennedy ! Great point on the visual introducing filter context. I meant to include information about the matrix I'd be using in the original message but forgot to do so. That's added now.

      To answer here - I would love to be able to use this measure in two ways:

      1. A KPI/Gauge that's something like the average for the current instructor with the goal as the department average. This would then only have the instructor as an added filter.
      2. A matrix that would have expandable rows for Instructor, Class, Question.

      I think the same measure would work for both, yes? Since the removal of filters on instructor_id/class_id/question_id should fufill both scenarios?

       

      I have used ALLSELECTED/ALLEXCEPT in the past, yes. I didn't try either of those yet. I'll give those a try tomorrow.

      • AllisonKennedy's avatar
        AllisonKennedy
        Community Champion

        cwollett  Yes, the same measure should work for both. How did you get on with using the ALLSELECTED? Have you solved this or do you still need further guidance?