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
Anonymous
Not applicable

Conteo Diferenciado Condicional

Necesito calcular las siguientes condiciones con un conjunto de datos en el que en última instancia recibiré una respuesta final distinta para cada ID (cada ID contiene 6 preguntas cada uno):

Preguntas 1-5Pregunta 6Respuesta final
CUALQUIERA " No""No"NO
TODO " "Sí" O "n/a""No"NO
CUALQUIERA " No""Sí" O "n/a"quizás
TODO " "Sí" O "n/a""Sí" O "n/a"

CONJUNTO DE DATOS DE EJEMPLO

IdPregunta #Respuesta
11
12
13No
14
15No
16
21
22
23
24
25
26No
31n/a
32No
33
34No
35
36

El resultado después de que se hayan aplicado las condiciones se agruparía algo así como:

IdRespuesta final
1
2quizás
3No

(la respuesta final anterior no es exacta con las condiciones para cada ID, pero simplemente compartir para dar una idea de cómo debe ser el resultado final)

Cualquier ayuda o punteros en la dirección correcta sería muy apreciado!!

¡Gracias!

4 REPLIES 4
nandukrishnavs
Super User
Super User

@kbig02

Aquí está la versión simplificada

FinalAnswer = 
var _onetofive= COMBINEVALUES(",",'Table'[Question 1],'Table'[Question 2],'Table'[Question 3],'Table'[Question 4],'Table'[Question 5])
var _six='Table'[Question 6]

var _condition1= IF(CONTAINSSTRING(_onetofive,"No") && (_six="No"),"NO")

var _condition2= IF(NOT(CONTAINSSTRING(_onetofive,"No")) && (_six="No"),"NO")

var _condition3= IF(CONTAINSSTRING(_onetofive,"No") && (_six IN {"Yes","n/a"}),"MAYBE")

var _condition4=IF(NOT(CONTAINSSTRING(_onetofive,"No")) &&(_six IN {"Yes","n/a"}),"YES")

VAR _result =
    SWITCH (
        TRUE (),
        NOT (
            ISBLANK ( _condition1 )
        ), _condition1,
        NOT (
            ISBLANK ( _condition2 )
        ), _condition2,
        NOT (
            ISBLANK ( _condition3 )
        ), _condition3,
        NOT (
            ISBLANK ( _condition4 )
        ), _condition4,
        "Not satisfied"
    )
RETURN
    _result



¿Respondí a tu pregunta? ¡Marca mi puesto como solución!
Apreciar con un kudos
🙂


Regards,
Nandu Krishna

Greg_Deckler
Super User
Super User

Tal vez algo como el PBIX adjunto.

The Final Answer = 
    VAR __Answer6 = MAXX(FILTER('Table',[Question #]=6),[Answer])
    VAR __Nos = COUNTROWS(FILTER('Table',[Answer]="No"))
    VAR __Yes = COUNTROWS(FILTER('Table','Table'[Answer]="Yes"))
    VAR __Answers = SELECTCOLUMNS('Table',"Answer",[Answer])
RETURN
    SWITCH(TRUE(),
        "No" IN __Answers || __Answer6 = "No","NO",
        NOT("No" IN __Answers) || __Answer6 = "No","NO",
        "No" IN __Answers && (__Answer6 = "Yes" || __Answer6 = "n/a"),"MAYBE",
        NOT("No" IN __Answers) && (__Answer6 = "Yes" || __Answer6 = "n/a"),
        "I'm sorry Dave, I can't do that"
    )


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Gracias Dave!

He pivotado la tabla y ahora estoy tratando de aplicar lo que compartió a esto:

IdPregunta 1Pregunta 2Pregunta 3Pregunta 4Pregunta 5Pregunta 6Respuesta final
1n/a
2Non/an/an/aNo
3NoNoNoNoNo
4n/aNoNo
5NoNoNoNoNoNo
6No
7n/an/aNoNoNo
8
9NoNoNoNoNo
10n/an/a

Sin embargo, seguí recibiendo una tabla de varios valores se proporcionó error...

¿Puedes ayudar?

@kbig02

Final Answer =
VAR _condition1 =
    IF (
        ( 'Table'[Question 1] = "No"
            || 'Table'[Question 2] = "No"
            || 'Table'[Question 3] = "No"
            || 'Table'[Question 4] = "No"
            || 'Table'[Question 5] = "No" )
            && ( 'Table'[Question 6] = "No" ),
        "NO"
    )
VAR _condition2 =
    IF (
        ( 'Table'[Question 1]
            IN {
            "Yes",
            "n/a"
        }
            && 'Table'[Question 2]
            IN {
            "Yes",
            "n/a"
        }
            && 'Table'[Question 3]
            IN {
            "Yes",
            "n/a"
        }
            && 'Table'[Question 4]
            IN {
            "Yes",
            "n/a"
        }
            && 'Table'[Question 5]
            IN {
            "Yes",
            "n/a"
        } )
            && ( 'Table'[Question 6] = "No" ),
        "NO"
    )
VAR _condition3 =
    IF (
        ( 'Table'[Question 1] = "No"
            || 'Table'[Question 2] = "No"
            || 'Table'[Question 3] = "No"
            || 'Table'[Question 4] = "No"
            || 'Table'[Question 5] = "No" )
            && ( 'Table'[Question 6]
            IN {
            "Yes",
            "n/a"
        } ),
        "MAYBE"
    )
VAR _condition4 =
    IF (
        ( 'Table'[Question 1]
            IN {
            "Yes",
            "n/a"
        } )
            && ( 'Table'[Question 2]
            IN {
            "Yes",
            "n/a"
        } )
            && ( 'Table'[Question 3]
            IN {
            "Yes",
            "n/a"
        } )
            && ( 'Table'[Question 4]
            IN {
            "Yes",
            "n/a"
        } )
            && ( 'Table'[Question 5]
            IN {
            "Yes",
            "n/a"
        } )
            && ( 'Table'[Question 6]
            IN {
            "Yes",
            "n/a"
        } ),
        "YES"
    )
VAR _result =
    SWITCH (
        TRUE (),
        NOT (
            ISBLANK ( _condition1 )
        ), _condition1,
        NOT (
            ISBLANK ( _condition2 )
        ), _condition2,
        NOT (
            ISBLANK ( _condition3 )
        ), _condition3,
        NOT (
            ISBLANK ( _condition4 )
        ), _condition4,
        "Not satisfied"
    )
RETURN
    _result

Capture.JPG



¿Respondí a tu pregunta? ¡Marca mi puesto como solución!
Apreciar con un kudos
🙂


Regards,
Nandu Krishna

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.