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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

Need help in adding a calculated column

Hi

I want to show the count of Exotic and Non Exotic Fruits and Vegetables. While I got the solution to count Exotic, I need help in counting the non exotic ones. I have an added table and there is just one table with name My_Farm_Data in which there are below mentioned columns Type and Sub Category. I want to add the column “Non Exotic” in which it should return the count of “Fruit” and “Vegetable” which are NOT “Exotic”

 

Type

Sub Category

Non Exotic

Fruit

Exotic

1

Fruit

Non Exotic

 

Vegetable

Exotic

1

Fruit

Exotic

1

Vegetable

Non Exotic

 

Dry Fruits

Imported

 

Spices

 

 

Spices

 

 

Spices

 

 

Dry Fruits

Imported

 

Fruit

Non Exotic

 

Vegetable

Non Exotic

 

Fruit

Exotic

1

Fruit

Imported

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

 

1.jpg

 

 

 

Non Exotic Col = if('Table'[Type] in {"Fruit","Vegetable"} && 'Table'[Sub Category] <> "Exotic",1,0)

 

 

 

 

NonEXoctic COunt = 
VAR Fruits =
    COUNTX (
        FILTER (
            'Table',
            'Table'[Type]
                IN {
                "Fruit"
            }
                && 'Table'[Sub Category] <> "Exotic"
        ),
        'Table'[Type]
    )
VAR veg =
    COUNTX (
        FILTER (
            'Table',
            'Table'[Type]
                IN {
                "Vegetable"
            }
                && 'Table'[Sub Category] <> "Exotic"
        ),
        'Table'[Type]
    )
RETURN
    SWITCH (
        TRUE (),
        'Table'[Type] = "Fruit" && 'Table'[Sub Category] = "Non Exotic", Fruits,
        'Table'[Type] = "Vegetable" && 'Table'[Sub Category] = "Non Exotic", veg,
        BLANK ()
    )


 

 

 

Regards,

Harsh Nathani


Appreciate with a Kudos!! (Click the Thumbs Up Button)

Did I answer your question? Mark my post as a solution!

 

View solution in original post

8 REPLIES 8
amitchandak
Super User
Super User

@Anonymous , with data not able separate input and out put

 

Only as column

Non Exotic = if([Type] in {"Fruit","Vegetable"} && [Sub Category] <> "Exotic",1,0)

 

Can work as column or measure . For column will give total in each row

countx(filter(Table,Table[Type] in {"Fruit","Vegetable"} && Table[Sub Category] <> "Exotic"),Table[Type])

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

Hi @Anonymous ,

 

 

1.jpg

 

 

 

Non Exotic Col = if('Table'[Type] in {"Fruit","Vegetable"} && 'Table'[Sub Category] <> "Exotic",1,0)

 

 

 

 

NonEXoctic COunt = 
VAR Fruits =
    COUNTX (
        FILTER (
            'Table',
            'Table'[Type]
                IN {
                "Fruit"
            }
                && 'Table'[Sub Category] <> "Exotic"
        ),
        'Table'[Type]
    )
VAR veg =
    COUNTX (
        FILTER (
            'Table',
            'Table'[Type]
                IN {
                "Vegetable"
            }
                && 'Table'[Sub Category] <> "Exotic"
        ),
        'Table'[Type]
    )
RETURN
    SWITCH (
        TRUE (),
        'Table'[Type] = "Fruit" && 'Table'[Sub Category] = "Non Exotic", Fruits,
        'Table'[Type] = "Vegetable" && 'Table'[Sub Category] = "Non Exotic", veg,
        BLANK ()
    )


 

 

 

Regards,

Harsh Nathani


Appreciate with a Kudos!! (Click the Thumbs Up Button)

Did I answer your question? Mark my post as a solution!

 

Anonymous
Not applicable

Thanks. Your solution - "Non Exotic Col" is what am looking for. so this is the approach am following - Am going to Transform > Add Column > Add Custom Column. For some reason am unable to choose the table name in the formula you have shown below 

Hi @Anonymous ,

 

Do not do this in Power Query.

 

Do this in Power BI Desktop.

 

1.jpg

 

 

Regards,

Harsh Nathani

Anonymous
Not applicable

Wow! that was easy, thanks! So what is the difference in adding a custom column and having this approach? when i change my data tomorrow will this still apply?

Hi @Anonymous ,

 

 

Yes, it will still apply.

 


Regards,

Harsh Nathani


Appreciate with a Kudos!! (Click the Thumbs Up Button)

Did I answer your question? Mark my post as a solution!

Anonymous
Not applicable

Awesome! Thanks so much.

az38
Community Champion
Community Champion

Hi @Anonymous 

try

Measure = 
CALCULATE(COUNTROWS('My_Farm_Data'),
'My_Farm_Data'[Type] IN {"Fruit", "Vegetable"}, 'My_Farm_Data'[Sub Category] <> "Exotic"
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors