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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Sandhya877
Frequent Visitor

Grouping of columns to Create new Column

In a table, I have two fields SubCategory1 and Subcategory1. I am creating a New Column : Category. 

SubCategory1       Subcategory2       quantity 

Accessories           Bike Racks                 5

Accessories           Bike Stands                7

Accessories            Bottels                      4

Accessories           Cleanign Supplies    3

Accessories         Hydration Packs          2

Accessories          Tires                          4

 

Logic: 

SubCategory1 = Accessories and Subcategory2 = Bike Racks and Bike Stands as Bike Accessories

SubCategory1 = Accessories and Subcategory2 = Bike Racks/Bike Stands/Bottels/Cleanign Supplies/Hydration Packs/ Tires as All Accessories

 

When i select All Accessories - I want to include everything under Subcategory2

when i select Bike Accessories - I want only to include Bike Racks and Bike Stands

 

I tried Switch and Nested If functions.  but  its filtering out the data for All Accessories. 

if(SubCategory1 = Accessories && Subcategory2 in {"Bike Racks", "Bike Stands"}, "Bike Accessories", 

If( SubCategory1 = Accessories && Subcategory2 in { Bike Racks/Bike Stands/Bottels/Cleanign Supplies/Hydration Packs/ Tires}, " All Accessories", "ERROR"))

 

Below is the output i am getting: 

Category                  Quantity

Bike Accessories            12 

All Accessories               13

 

I should get 25, but I am getting 13.  

how can i write a dax without the data being filtered out ??

Thank you. 

7 REPLIES 7
Anonymous
Not applicable

Hi @Sandhya877 ,

I created a sample pbix file(see the attachement), please check if that is what you want.

1. Create a dimension table as below

vyiruanmsft_1-1698393039759.png

2. Create a measure as below

 

Measure = 
VAR _category =
    SELECTEDVALUE ( 'Category'[Category] )
RETURN
    SWITCH (
        _category,
        "Bike Accessories",
            CALCULATE (
                SUM ( 'Table'[quantity] ),
                FILTER (
                    'Table',
                    'Table'[SubCategory1] = "Accessories"
                        && 'Table'[Subcategory2] IN { "Bike Racks", "Bike Stands" }
                )
            ),
        "All Accessories",
            CALCULATE (
                SUM ( 'Table'[quantity] ),
                FILTER (
                    'Table',
                    'Table'[SubCategory1] = "Accessories"
                        && 'Table'[Subcategory2]
                        IN {
                            "Bike Racks",
                            "Bike Stands",
                            "Bottels",
                            "Cleanign Supplies",
                            "Hydration Packs",
                            "Tires"
                        }
                )
            )
    )

 

vyiruanmsft_0-1698392869130.png

Best Regards

Thank you. this is helpful, What if the subcategory2 is another related table ?

Anonymous
Not applicable

Hi @Sandhya877 ,

Thanks for your feedback. Since the subcategory2 is another related table, could you please provide some raw data in these tables (exclude sensitive data) with Text format and the relation info(cardinality, based field etc) if it created any relationship with the other table. It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

I am not a super user to upload the pbix file.

Anonymous
Not applicable

Hi @Sandhya877 ,

It's OK. You can refer the following link to paste the sample data with Text format in your reply directly. And please share the relation info(cardinality, based field etc) if table which the field [subcategory2] exist in created any relationship with the other table. Thank you.

How to provide sample data in the Power BI Forum

Best Regards

lbendlin
Super User
Super User

I would recommend you use either Power Query or the upstream data source for that.  There's no reason to do this in DAX.

I have like thousands of row, i just used sample data. I do not think power query would be better option. 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.