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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
newbiepbix
Microsoft Employee
Microsoft Employee

Grouping rows based on conditions

Hi Everyone,

I am new to PBI and needed some help.I have a scenario where i need the rows to be merged / grouped:

The below table is what i have in my data :

 

TitleType

A

Both
APart1 only
APart2 only
ANA
BPart1 only
BPart2 only
BNA
CPart1 only
CNA
DPart2 only
DNA
ENA

 

and the below table is what I am looking to get :

 

TitleType
ABoth
BBoth
CPart1 only
DPart2 only
ENA

 

Explanation : Both > Part1 AND Part2 > Part1 > Part 2 > NA.

(In case of Title B it comes as Both because it has two separate Part1 and Part2)

If anyone could please help me out it would be of great help.

 

Thanks!

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

hi  @newbiepbix 

Just use this logic to create a new table

New Table = 
    SUMMARIZE (
        'Table',
        'Table'[Title],
        "Type", IF (
            "Both" IN VALUES ( 'Table'[Type] ),
            "Both",
            IF (
                "Part1 only" IN VALUES ( 'Table'[Type] )
                    && "Part2 only" IN VALUES ( 'Table'[Type] ),
                "Both",
                IF (
                    "Part1 only" IN VALUES ( 'Table'[Type] ),
                    "Part1 only",
                    IF ( "Part2 only" IN VALUES ( 'Table'[Type] ), "Part2 only", "NA" )
                )
            )
        )
    )

Result:

1.JPG

 

and here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
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

3 REPLIES 3
v-lili6-msft
Community Support
Community Support

hi  @newbiepbix 

Just use this logic to create a new table

New Table = 
    SUMMARIZE (
        'Table',
        'Table'[Title],
        "Type", IF (
            "Both" IN VALUES ( 'Table'[Type] ),
            "Both",
            IF (
                "Part1 only" IN VALUES ( 'Table'[Type] )
                    && "Part2 only" IN VALUES ( 'Table'[Type] ),
                "Both",
                IF (
                    "Part1 only" IN VALUES ( 'Table'[Type] ),
                    "Part1 only",
                    IF ( "Part2 only" IN VALUES ( 'Table'[Type] ), "Part2 only", "NA" )
                )
            )
        )
    )

Result:

1.JPG

 

and here is sample pbix file, please try it.

 

Regards,

Lin

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

Thank you so much!!!! This worked like a charm.

amitchandak
Super User
Super User

@newbiepbix , create a new measure like this and try

 

new measure =Switch(
countx(filter(table,table[Type]="Both"),table[Title])>=1,"Both",
countx(filter(table,table[Type]="Part1 AND Part2"),table[Title])>=1,"Part1 AND Part2",
countx(filter(table,table[Type]="Part1"),table[Title])>=1,"Part1",
countx(filter(table,table[Type]="Part 2"),table[Title])>=1,"Part 2",
"NA"
)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.