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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
luisvieira95
Frequent Visitor

Custom column with multiple If statements for picking row below

Hi!

I'm developing a DAX formula to show the projects that obey the rule below:

 

IF (ACTIVITY = A2  AND STATUS= ENCERRADO) AND (ACTIVITY = A3 AND STATUS= PENDENTE):
COLUMN FORMULA = "TRUE"

ELSE:

BLANK

 

PROJECTACTIVITYSTATUS
P1A1ENCERRADO
P1A2PENDENTE
P1A3PENDENTE
P1A4PENDENTE
P1A5PENDENTE
P2A1ENCERRADO
P2A2ENCERRADO
P2A3PENDENTE
P2A4PENDENTE
P2A5PENDENTE
P3A1ENCERRADO
P3A2ENCERRADO
P3A3ENCERRADO
P3A4PENDENTE
P3A5PENDENTE
P4A1ENCERRADO
P4A2ENCERRADO
P4A3PENDENTE
P4A4PENDENTE
P4A5PENDENTE

 

 

 

CORRECT ANSWER:

 

 

P1A1ENCERRADOJUN 
P1A2PENDENTEA2PENDENTE 
P1A3PENDENTEA3PENDENTE 
P1A4PENDENTEA4PENDENTE 
P1A5PENDENTEA5PENDENTE 
P2A1ENCERRADOA1ENCERRADO 
P2A2ENCERRADOA2ENCERRADOTRUE
P2A3PENDENTEA3PENDENTETRUE
P2A4PENDENTEA4PENDENTE 
P2A5PENDENTEA5PENDENTE 
P3A1ENCERRADOA1ENCERRADO 
P3A2ENCERRADOA2ENCERRADO 
P3A3ENCERRADOA3ENCERRADO 
P3A4PENDENTEA4PENDENTE 
P3A5PENDENTEA5PENDENTE 
P4A1ENCERRADOA1ENCERRADO 
P4A2ENCERRADOA2ENCERRADOTRUE
P4A3PENDENTEA3PENDENTETRUE
P4A4PENDENTEA4PENDENTE 
P4A5PENDENTEA5PENDENTE 

 

How can my dax formula pick up the valeu below the first if statement to show the correct project?

I have made this formula concatenating the  ACTIVITY and STATUS columns, but it doesnt show all the projects because its missing a IF statement

 COND = IF(teste[JUN] = "A2ENCERRADO";"TRUE";BLANK())

1 ACCEPTED SOLUTION

I found a solution

First I made a calculated column

 

Column = IF (
    OR (
        AND ( teste[ACTIVITY] = "A2"; teste[ESTATUS] = "ENCERRADO" );   
        AND ( teste[ACTIVITY] = "A3"; teste[ESTATUS] = "PENDENTE" )
    );
    TRUE ();
    FALSE()
)

And than a measure with a slicer to get only true subjects in a sequence

 

 

Column 3 = COUNTROWS(filter(teste;teste[Column]=TRUE()))

 

View solution in original post

6 REPLIES 6
themistoklis
Community Champion
Community Champion

@ibarrau

 

You can also use the switch function:

 

Column =
SWITCH (
    TRUE ();
    'Table'[Activity] = 'A2' && 'Table'[Status] = 'ENCERRADO'; 'TRUE';
    'Table'[Activity] = 'A3' && 'Table'[Status] = 'PENDENTE'; 'TRUE';
    BLANK()
)

 

ibarrau
Super User
Super User

Hi, you can try && instead of AND in your formula or can try "AND" dax function: 

 

= IF (
    AND (
        AND ( ACTIVITY = A2, STATUS = ENCERRADO ),
        AND ( ACTIVITY = A3, STATUS = PENDENTE )
    ),
    TRUE (),
    BLANK ()
)

 

Let me know if it works 

 


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

 


Hello, thank you for your support, but with this formula every result in the custom column was "False"

 

 

 

CODIGO = IF (
    AND (
        AND ( teste[ACTIVITY] = "A2"; teste[STATUS] = "ENCERRADO" );
        AND ( teste[ACTIVITY] = "A3"; teste[STATUS] = "PENDENTE" )
    );
    TRUE ();
    BLANK ()
)

Are you sure you have to ask with AND? this means all the columns should respond to that condition in order to show true(). Maybe you need an "OR" in some place.

 

 I think you are looking for this:

= IF (
    OR (
        AND ( ACTIVITY = A2, STATUS = ENCERRADO ),
        AND ( ACTIVITY = A3, STATUS = PENDENTE )
    ),
    TRUE (),
    BLANK ()
)

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

I tried to use the conditionals but they did not work.
Only if A2 and A3 are in the sequence reported in the correct answer that the formula must be correct as well.

IF A2 = ENCERRADO and next line A3 = PENDENTE:
"TRUE"
ELSE:
"FALSE"

I found a solution

First I made a calculated column

 

Column = IF (
    OR (
        AND ( teste[ACTIVITY] = "A2"; teste[ESTATUS] = "ENCERRADO" );   
        AND ( teste[ACTIVITY] = "A3"; teste[ESTATUS] = "PENDENTE" )
    );
    TRUE ();
    FALSE()
)

And than a measure with a slicer to get only true subjects in a sequence

 

 

Column 3 = COUNTROWS(filter(teste;teste[Column]=TRUE()))

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.