cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors