Forum Discussion

daniellf's avatar
daniellf
Frequent Visitor
7 years ago
Solved

New column based on 3 others

I'm summarizing the results of a survey and need to exclude results from part of the population.

 

Considering the example table below, I'd like to create a column in the table which will indicate that an employee's answers should be excluded from the analysis if they did not answer a, b and c at least once(no matter what question). In the below, only John's answers would be considered valid.

 

How can I create this column 'Valid' keeping in mind that I have 15k unique employees.

 

 

EmployeeQuestionAnswerValid
Anna1ano
Anna2ano
Anna3ano
Anna4ano
Anna5bno
Anna6ano
John1ayes
John2byes
John3cyes
John4cyes
John5cyes
John6cyes
Blake1cno
Blake2bno
Blake3cno
Blake4bno
Blake5cno
Blake6bno
  • Hi daniellf ,

     

    If the "a,b,c" means all the answer, we can use following DAX to meet your requirement.

     

    V = 
    VAR e = [Employee]
    VAR result =
        COUNTROWS (
            DISTINCT (
                SELECTCOLUMNS ( FILTER ( Table1, 'Table1'[Employee] = e ), "A", [Answer] )
            )
        )
    RETURN
        IF ( result = 3, "yes", "no" )

    number 3 means the answer number

     

     

    BTW, pbix as attached.

     

    Best regards,

    Community Support Team _ Dong Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 Replies

  • SteveCampbell's avatar
    SteveCampbell
    Icon for Memorable Member rankMemorable Member

     

    Valid =
    VAR _AnswerString = "a,b,c"
    VAR _emplID = SELECTEDVALUE ( 'YourTable'[Employee] )
    RETURN
        IF (
            CONCATENATEX (
                CALCULATETABLE (VALUES ( 'YourTable'[Answer] ), 'YourTable'[Employee] = _emplID),
                'YourTable'[Answer],"," ) 
    = _AnswerString, "Yes","No" )

     

    You can change the VAR _AnswerString = "" to be a list of accepted answers, separated by commas

     

     

    Love hearing about Power BI tips, jobs and news?
    I love to share about these - connect with me!

    Stay up to date on  
    Read my blogs on  

  • v-lid-msft's avatar
    v-lid-msft
    Icon for Community Support rankCommunity Support

    Hi daniellf ,

     

    If the "a,b,c" means all the answer, we can use following DAX to meet your requirement.

     

    V = 
    VAR e = [Employee]
    VAR result =
        COUNTROWS (
            DISTINCT (
                SELECTCOLUMNS ( FILTER ( Table1, 'Table1'[Employee] = e ), "A", [Answer] )
            )
        )
    RETURN
        IF ( result = 3, "yes", "no" )

    number 3 means the answer number

     

     

    BTW, pbix as attached.

     

    Best regards,

    Community Support Team _ Dong Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.