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
joshua1990
Post Prodigy
Post Prodigy

False result for calculation on lower granularity

Hello everybody.

I have a simple calculation of [Inventory]-[Sales]. I need the result if it is negative otherwise, there should be a blank.

In the ItemMaster there are two levels: Area and Item.

My current approach is not working. It shows me no result on Area-level - as you can see:

AreaItemSalesInventoryInventory-Sales
A1144457,1812500-31957,18
 2 215000 
 3486829,7115315000-171829,712
Result 531286,8915542500

 

 

The function is:

 

=IF(SUMX('Item Master';[Inventory])-SUMX(Sales;[Sales])<0;SUMX('Item Master';[Inventory])-SUMX(Sales;[Sales]);BLANK())

 

 

Does someone know where my mistake is?

 

 

4 REPLIES 4
Anonymous
Not applicable

Hi  @joshua1990 

 

The filter context on the Result line is the whole table. Totals are not the sum of the indivudal lines, but are calculated according the filter context. 

 

So if you make sure that your filter context only filters the negative values then the result line will show that value. 

 

I created two measures under the assumption that the values are in one record (otherwise you need to adjust the measures): 

Inventory_Sales = SUM(ItemMaster[Inventory]) - Sum(ItemMaster[Sales])

Inventory_Sales Negatives Only = SUMX(
filter('ItemMaster',
'ItemMaster'[Inventory]<ItemMaster[Sales]),
[Inventory_Sales]
)

2020-01-05 22_14_45-sample tables - Power BI Desktop.jpg

 

Hope this helps.

 

 
az38
Community Champion
Community Champion

Hi @joshua1990 

try to use calculate for correct row context usage and maybe SUM instead of SUMX

for example

Measure =
var Expression = CALCULATE(SUM('Item Master'[Inventory]))-CALCULATE(SUM(Sales[Sales]))
RETURN
IF (Expression < 0;Expression; BLANK())

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

 


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

Hi Joshua1990

 

Can you just clarify what you mean regarding your two levels, I don't understand, do you mean there are two types of record in the data table? Could you include a screen shot of the data?

 

Are you expecting a value in the Inventory-Sales column against the Result row? It's blank because it's not a negative number.

 

 

Hey @cpearson Thanks for your support!

I just mean there are two granularities like this:

AreaItem
AA1
AA2
BB1

 

I would expect the sum of both negative values 🙂

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.