Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
calerof
Impactful Individual
Impactful Individual

Rate a Microsoft Forms Survey with choice questions using LOOKUPVALUE

Hello,

 

I'm trying to rate a survey made with Microsoft Forms with choice questions using the LOOKUPVALUE function. 

 

I made a sample data file and it's working, but in my actual data it's not, I receive the error message:

"A table of multiple values was supplied where a single value was expected".

 

1. Sample data

 

I have three tables in this excel file:

  • Questions, including only 5 questions with 5 choices each, i.e.
    • Always, Most time, Some time, Almost never, Never.
  • Rating_table: Valuation of answers, each question has its own valuation, as follows (I unpivoted it in Power Query):rating.png
  • Answers of two survey participants for this sample:
  • Answers.png

After cleaning the data I try to value each answer with this code:

Answer value = 
LOOKUPVALUE(
    Rating_table3[Value],
    Rating_table3[Option],
    Answers1[Answer],
    Rating_table3[Question number],
    Answers1[Question Number]
)

This works fine:

sample valuation.png

PBIX file

 

2. Actual Data

 

Same procedures. Here are my files:

Answers

Questions

Valuation table

 

Code:

Respuesta Valor = 
LOOKUPVALUE(
    Tabla51[Valor],
    Tabla51[Opcion],
    Respuestas[Respuesta],
    Tabla51[Item],
    Respuestas[Pregunta Num]
)

PBIX file

 

I'd really appreciate your support.

 

Best regards,

 

Fernando

 

1 ACCEPTED SOLUTION

Hi @calerof ,

 

When you use the lookupvalue, you condition may filter more than 1 rows, you can test it like following.

 

13.PNG14.PNG15.PNG

 

if you just want negativa value, we can use the following formula.

 

Respuesta Valor =
VAR t =
    CALCULATE (
        COUNTROWS ( 'Tabla51' ),
        FILTER (
            'Tabla51',
            Tabla51[Opcion] = [Respuesta]
                && Tabla51[Item] = [Pregunta Num]
        )
    )
VAR result =
    IF (
        t = 1,
        LOOKUPVALUE (
            Tabla51[Valor],
            Tabla51[Opcion], Respuestas[Respuesta],
            Tabla51[Item], Respuestas[Pregunta Num]
        ),
        VAR s = "Negativa" -- or other conditon you want
        RETURN
            MAXX (
                FILTER (
                    'Tabla51',
                    Tabla51[Opcion] = [Respuesta]
                        && Tabla51[Item] = [Pregunta Num]
                        && Tabla51[Expresividad] = s
                ),
                [Valor]
            )
    )
RETURN
    result

or jump the judge, just use the maxx/minx function.

 

16.PNG


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.

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.

View solution in original post

4 REPLIES 4
TomMartens
Super User
Super User

Hey,

 

first things first, thanks providing a great explanation and all the sample data you provided as well.

 

As I'm currently running out of time I will provide just this link: https://www.daxpatterns.com/survey/

The article explains how survey data can be analyzed using a tabular model.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
calerof
Impactful Individual
Impactful Individual

Thanks Tom, I'll review it right away.

Fernando

 

Hi @calerof ,

 

When you use the lookupvalue, you condition may filter more than 1 rows, you can test it like following.

 

13.PNG14.PNG15.PNG

 

if you just want negativa value, we can use the following formula.

 

Respuesta Valor =
VAR t =
    CALCULATE (
        COUNTROWS ( 'Tabla51' ),
        FILTER (
            'Tabla51',
            Tabla51[Opcion] = [Respuesta]
                && Tabla51[Item] = [Pregunta Num]
        )
    )
VAR result =
    IF (
        t = 1,
        LOOKUPVALUE (
            Tabla51[Valor],
            Tabla51[Opcion], Respuestas[Respuesta],
            Tabla51[Item], Respuestas[Pregunta Num]
        ),
        VAR s = "Negativa" -- or other conditon you want
        RETURN
            MAXX (
                FILTER (
                    'Tabla51',
                    Tabla51[Opcion] = [Respuesta]
                        && Tabla51[Item] = [Pregunta Num]
                        && Tabla51[Expresividad] = s
                ),
                [Valor]
            )
    )
RETURN
    result

or jump the judge, just use the maxx/minx function.

 

16.PNG


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.

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.
calerof
Impactful Individual
Impactful Individual

Hi @v-lid-msft ,

 

Thank you very much for your response and the time to review my model. After reviewing your solution and rechecking my data, you made me realize that in my Valuation table (Table51) I had a duplicated record, i.e. question # 54, thus producing the error in the LOOKUPVALUE calculated column. After eliminating the duplicated value the code works smoothly:

Respuesta Val = 
LOOKUPVALUE(
    Tabla51[Valor],
    Tabla51[Opcion],
    Respuestas_valuadas1[Respuesta],
    Tabla51[Item],
    Respuestas_valuadas1[Pregunta_Num]
)

It's always great to have the Community's support.

 

Cheers,

 

Fernando

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.