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
rpatel92
New Member

Measure to sum based on multiple category scenarios

Hello,

 

Trying to create a measure to sum based on the categories, but also looking to get it to add addtional amounts. I have an example of data below and the output I am looking for.

 

DATA

Sales
Category NoCategorySales
1001Cauliflower1
1002Orange3
1003Potato4
1004Apple1
1005Banana4
1006Onion2
1001Cauliflower2
1002Orange7
1003Potato1
1004Apple2
1005Banana3
1006Onion2
1001Cauliflower1
1002Orange5
1003Potato3
1004Apple2
1005Banana3
1006Onion2

 

OUTPUT

Items
Category NoCategorySum Amount
1001Cauliflower4
1002Orange15
1003Potato8
1004Apple5
1005Banana10
1006Onion6
1007Vegetables18
1008Fruits30

 

Basically looking to get the measure to SUM for Vegetables and Fruits, but I am unable to do so at the moment. Ofcourse, the actual data is more complex and can't sahre for obvious reasons. Below is what I have treid so far with not much luck.

 

Amount =
    VAR CAT = SELECTEDVALUE(CATEGORY)
    VAR TAMT= CALCULATE(sum(Sales))
    VAR VAMT = CALCULATE(sum(Sales),CATEGORY = "CAULIFLOWER"||CATEGORY = "POTATO"||CATEGORY = "ONION")
    VAR FAMT = CALCULATE(sum(Sales),CATEGORY = "ORANGE"||CATEGORY = "APPLE"||CATEGORY = "BANANA")
    VAR AMT = If(CAT = "VEGETABLE", VAMT,
                If(CAT = "FRUIT", FAMT,
                    TAMT))
    RETURN AMT
 
Appreciate any help that you provide. Thank you.
1 ACCEPTED SOLUTION
sjoerdvn
Super User
Super User

For this, I would implement helper dimensions.
First, the one that is to be used in the final report visual

 

Master_categories

Category No Category
1001 Cauliflower
1002 Orange
1003 Potato
1004 Apple
1005 Banana
1006 Onion
1007 Vegetables
1008 Fruits

 

Next, an intermediary one

Category No Category Master Category No
1001 Cauliflower 1007
1001 Cauliflower 1001
1002 Orange 1008
1002 Orange 1002
1003 Potato 1007
1003 Potato 1003
1004 Apple 1008
1004 Apple 1004
1005 Banana 1008
1005 Banana 1005
1006 Onion 1007
1006 Onion 1006
1007 Vegetables 1007
1008 Fruits 1008

 

Now create a bi-directional relationship between the master categories table and the intermediary categories table, and a single relationship between the intermediary table and the data table.
Now, in you visual you can select the columsn from the master categories table and the sum from the data table.

View solution in original post

4 REPLIES 4
sjoerdvn
Super User
Super User

For this, I would implement helper dimensions.
First, the one that is to be used in the final report visual

 

Master_categories

Category No Category
1001 Cauliflower
1002 Orange
1003 Potato
1004 Apple
1005 Banana
1006 Onion
1007 Vegetables
1008 Fruits

 

Next, an intermediary one

Category No Category Master Category No
1001 Cauliflower 1007
1001 Cauliflower 1001
1002 Orange 1008
1002 Orange 1002
1003 Potato 1007
1003 Potato 1003
1004 Apple 1008
1004 Apple 1004
1005 Banana 1008
1005 Banana 1005
1006 Onion 1007
1006 Onion 1006
1007 Vegetables 1007
1008 Fruits 1008

 

Now create a bi-directional relationship between the master categories table and the intermediary categories table, and a single relationship between the intermediary table and the data table.
Now, in you visual you can select the columsn from the master categories table and the sum from the data table.

Anonymous
Not applicable

Hi @rpatel92 ,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information and description to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

d_m_LNK
Resolver II
Resolver II

You could create a calculated column to persist a new subcategory of Vegetable or Fruit to a new calculated column in your table.  You could then do two simple calculate measures for Fruits and vegetables.

 

Calculated Column could be:

Sales[Subcategory] = 

SWITCH(TRUE(),

Sales[CATEGORY] IN {"CAULIFLOWER", "POTATO", "ONION"}, "Vegetable",

Sales[Category] IN {"Orange", "Apple", "Banana"}, "Fruit", "Uncategorized"

)

 

Then your Measures could be

Vegetable Sum = Calculate(Sum(Sales), Sales[Subcategory] = "Vegetable")

Fruit Sum = Calculate(Sum(Sales), Sales[Subcategory] = "Fruit")

 

 

Thank you David, going to give that a try over the weekend and see if that works. Appreacite the input.

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.