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
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
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.