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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
peaky
Frequent Visitor

Calculate value based on different collumn

Hello, 

I've two tables A and B as below. I would like to SUM values from table A based on category and divide them by table B based on other category. Is that possible?

 

Main goal is to: sum VALUE from table A where category = "A" and divide it by sum of Value from table B where Description = "In Storage". Is it possible? I've tried to use IF, SWITCH, CALCULATE and also separate collumns on 'Storage Costs' and 'Other costs' based on category but it didn't help.

 

Here is my function

CALC =

Switch(TRUE(),

'Table A'[Category] = "A", SUM('Table A'[Storage Costs])/Calculate(SUM('Table B'[Value]'),'Table B'[Description] = "In Storage"), 

SUM('Table A'[Other Costs])/Calculate(SUM('Table B'[Value]'),'Table B'[Description] = "Added to storage")

but when I use function above error occures:

A single value for column 'Category' in table 'Table A' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

 

I think it's important to mention that those 2 tables are connected witch each other by relationships on 5 collumns like months, years, entities, scenarios and business lines. I've created additional 5 relationship tables so that I can filter them both on those 5 dimensions.

 

Table A

MonthCategoryValueStorage CostsOther costs

JAN

A

10100
JANB20020
JANC30030
JANA15150
JANA25250
JANC35035
JANA11110
JANB12012
JANA13120

 

 

Table B

MONTHDimensionDescriptionValue
JANTXAdded to storage40
JANTXIn Storage5000
JANFXAdded to storage50
JANFXAdded to storage60
JANTXAdded to storage70
JANFXIn Storage2000
JANHXIn Storage3000
JANYXIn Storage4000
JANIXIn Storage6000
4 REPLIES 4
johnt75
Super User
Super User

Try

My Measure =
VAR tableAValue =
    CALCULATE ( SUM ( 'Table A'[Value] ), 'Table A'[Category] = "A" )
VAR tableBValue =
    CALCULATE ( SUM ( 'Table B'[Value] ), 'Table B'[Description] = "In Storage" )
RETURN
    DIVIDE ( tableAValue, tableBValue )
peaky
Frequent Visitor

And how I can inclued those 2 variances in 1 measure? I mean I want to have in one measure divided category A by In storage and category B or C by Added to Storage.

It depends on how the measure will be displayed. If you're going to be including the category in the visual, then you can use SELECTEDVALUE to determine which category is in context, but if you're not going to have the category then you would need to use an iterator to introduce that context

peaky
Frequent Visitor

Okay and is there a way to achieve this using switch(true()) function? Every time the error occures about determining single value in collumn.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.