cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
gauravnarchal
Post Prodigy
Post Prodigy

Help with DAX

Hello

 

How can I write a Dax to get the TYPE against each team?

 

If TYPE is 6032 or 6031 or 6000 and matches the identifier in the next row return type of the first identifier else TYPE

 

Thanks

Gaurav

 

Data

 

Table 1

 

IdentifierTypeTeam
20438266032 
20438266012Juniper Team
2043826309Pacific Team
20437856032 
20437856012Pacific Team
20437896000 
20437896012Mars Team
20438026000 
20438026012Desert Stallion
20438086000 
20438086012Pacific Team
20438116030 
20438116012Juniper Team
20438186000 
20438186012Mars Team
20438416031 
20438416012Sun Team
20438446000 
20438446012Juniper Team

 

Result

 

IdentifierTypeTeamPattern
20438266032  
20438266012Juniper Team6032
2043826309Pacific Team309
20437856032  
20437856012Pacific Team6032
20437896000  
20437896012Mars Team6000
20438026000  
20438026012Desert Stallion6000
20438086000  
20438086012Pacific Team6000
20438116030  
20438116012Juniper Team6030
20438186000  
20438186012Mars Team6000
20438416031  
20438416012Sun Team6000
20438446000  
20438446012Juniper Team6000
1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @gauravnarchal ,

 

Here's my solution.

1.Add an index column in Power Query Editor.

vstephenmsft_0-1675058681484.png

vstephenmsft_1-1675058715831.png

 

2.Add a calculated column in Power BI Desktop.

Pattern =
VAR _previousType =
    CALCULATE (
        MAX ( 'Table'[Type] ),
        FILTER (
            'Table',
            [Identifier] = EARLIER ( 'Table'[Identifier] )
                && [Index] < EARLIER ( 'Table'[Index] )
        )
    )
VAR _previousTeam =
    CALCULATE (
        MAX ( 'Table'[Team] ),
        FILTER (
            'Table',
            [Identifier] = EARLIER ( 'Table'[Identifier] )
                && [Index] < EARLIER ( 'Table'[Index] )
        )
    )
RETURN
    IF (
        ISBLANK ( [Team] ),
        BLANK (),
        IF ( ISBLANK ( _previousTeam ), _previousType, [Type] )
    )

vstephenmsft_2-1675058775010.png

   

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

1 REPLY 1
v-stephen-msft
Community Support
Community Support

Hi @gauravnarchal ,

 

Here's my solution.

1.Add an index column in Power Query Editor.

vstephenmsft_0-1675058681484.png

vstephenmsft_1-1675058715831.png

 

2.Add a calculated column in Power BI Desktop.

Pattern =
VAR _previousType =
    CALCULATE (
        MAX ( 'Table'[Type] ),
        FILTER (
            'Table',
            [Identifier] = EARLIER ( 'Table'[Identifier] )
                && [Index] < EARLIER ( 'Table'[Index] )
        )
    )
VAR _previousTeam =
    CALCULATE (
        MAX ( 'Table'[Team] ),
        FILTER (
            'Table',
            [Identifier] = EARLIER ( 'Table'[Identifier] )
                && [Index] < EARLIER ( 'Table'[Index] )
        )
    )
RETURN
    IF (
        ISBLANK ( [Team] ),
        BLANK (),
        IF ( ISBLANK ( _previousTeam ), _previousType, [Type] )
    )

vstephenmsft_2-1675058775010.png

   

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

Helpful resources

Announcements
Vote for T-Shirt Design

Power BI T-Shirt Design Challenge 2023

Vote for your favorite t-shirt design now through March 28.

March 2023 Update3

Power BI March 2023 Update

Find out more about the March 2023 update.

March Events 2023A

March 2023 Events

Find out more about the online and in person events happening in March!

Top Solution Authors