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
Anonymous
Not applicable

In Matrix Visual - Totals to only sum values greater than 0

Hi, I'm currently calculating the current inventory on hand. This is done by summing all movement from previous dates and including the current date. Some days that are negative movements and when obtaining the current inventory it can be negative too. Hence, when presenting the current inventory data in a matrix form, I would like the totals to only sum the positive values and not the negative values. Thanks!

 

Sample Data:

ProductMovementDate
A21/1/2020
A41/2/2020
A51/3/2020
A-91/4/2020
A71/5/2020
A31/6/2020
A11/7/2020
A-31/8/2020
A51/9/2020
A81/10/2020
A101/11/2020
A111/12/2020
B21/1/2020
B-71/2/2020
B51/3/2020
B-91/4/2020
B-71/5/2020
B31/6/2020
B11/7/2020
B-31/8/2020
B-51/9/2020
B81/10/2020
B-101/11/2020
B111/12/2020
C21/1/2020
C51/2/2020
C-31/3/2020
C41/4/2020
C-71/5/2020
C81/6/2020
C11/7/2020
C101/8/2020
C111/9/2020
C-81/10/2020
C121/11/2020
C-51/12/2020
 

Formulas:

1)

Current Inventory =
SWITCH(
TRUE(),
ROUND([Raw Current Inventory],0)=0,BLANK(),
[Raw Current Inventory]<0,BLANK(),
[Raw Current Inventory]
)
 
2)
Raw Current Inventory =
var _currdate=MAX('Table'[Date])
return

CALCULATE(
SUM('Table'[Movement]),
FILTER(
ALLSELECTED('Table'[Date]),
ISONORAFTER('Table'[Date], _currdate, DESC)
)
)

 

Power BI Visuals:

Question.png

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

I have updated my sample pbix file, please check whether that is what you want. You only need to create a measure as below:

Current Inventory = 
VAR _tab =
    SUMMARIZE (
        'Table',
        'Table'[Date],
        'Table'[Plant],
        'Table'[Product],
        "sMovement", IF ( SUM ( 'Table'[Movement] ) < 0, BLANK (), SUM ( 'Table'[Movement] ) )
    )
RETURN
    SUMX ( _tab, [sMovement] )

In Matrix Visual - Totals to only sum values greater than 0(Updated).JPG

Best Regards
Community Support Team _ Rena Ruan
If this post helps, then please consider Accept it as the solution to help the other members find it more.

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@Anonymous , prefer a date table so that you can correct inventory by product. Else you have also add product =max product 

Try measure

CALCULATE(
SUMX(filter('Table','Table'[Movement] >0)'Table'[Movement]),
FILTER(
ALLSELECTED('DATE'[Date]),'DATE'[Date] <=max('DATE'[Date])
)
)

 

or

 

CALCULATE(
SUM('Table'[Movement]),
FILTER(
ALLSELECTED('DATE'[Date]),'DATE'[Date] <=max('DATE'[Date])
)
)

 

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
Anonymous
Not applicable

@amitchandak Thanks for your quick response! I just added a date table. Tried your first measure and it works, but it's not what I want. That measure directly excludes all negative movement, but I want to include negative movement as well. I just don't want a negative value in the max date's current inventory total. So, according to the above example, on the maximum date, I have Product A= 44, Product B = -11, Product C = 30. I want the total in matrix form to show 44+30, not 44-11+30, i.e. ignore the negative values in the total.

The second measure you suggested is the same as what I'm doing now for "Raw Current Inventory".

question 1a.png

Anonymous
Not applicable

Hi @Anonymous ,

You can create two measures as below:

Measure = 
VAR _smovement=CALCULATE(SUM('Table'[Movement]),FILTER('Table','Table'[Product]=MAX('Table'[Product])))
RETURN  
IF(_smovement<0,BLANK(),_smovement)
Current Inventory = SUMX(VALUES('Table'[Product]),[Measure])

In Matrix Visual - Totals to only sum values greater than 0.JPG

Best Regards
Community Support Team _ Rena Ruan
If this post helps, then please consider Accept it as the solution to help the other members find it more.

Anonymous
Not applicable

Hi @Anonymous ,

 

thanks for your response! your solution does give the desired total. However, I just found out that when I add another field "Plant", I don't get values in matrix form for days where there aren't any movement. This doesn't happen when I don't add plant though (I get the desired data presentation and total when I only include product in the matrix and not plant). I would like to get daily volume, irregardless of whether there was movement or not.

 

Here's what I get now: (the one on the left is using my measure, while the one on the right uses your measure)

response.png

Without plant included: (I get the desired presentation and total with your measure)
2nd response.png

 

Here's the updated data with plant:

ProductMovementDatePlant

A201-Jan-20F
B201-Jan-20F
C201-Jan-20F
A402-Jan-20F
B-702-Jan-20G
C502-Jan-20G
A503-Jan-20G
B503-Jan-20F
C-303-Jan-20F
A-904-Jan-20F
B-904-Jan-20F
C 04-Jan-20F
A705-Jan-20F
B-705-Jan-20G
C-705-Jan-20G
A 06-Jan-20G
B306-Jan-20G
C-806-Jan-20G
A107-Jan-20G
B107-Jan-20F
C107-Jan-20F
A-308-Jan-20F
B-308-Jan-20F
C1008-Jan-20F
A509-Jan-20F
B-509-Jan-20F
C1109-Jan-20F
A810-Jan-20F
B810-Jan-20F
C-810-Jan-20F
A1011-Jan-20G
B-1011-Jan-20G
C1211-Jan-20G
A1112-Jan-20G
B1112-Jan-20G
C-512-Jan-20G
Anonymous
Not applicable

Hi @Anonymous ,

I have updated my sample pbix file, please check whether that is what you want. You only need to create a measure as below:

Current Inventory = 
VAR _tab =
    SUMMARIZE (
        'Table',
        'Table'[Date],
        'Table'[Plant],
        'Table'[Product],
        "sMovement", IF ( SUM ( 'Table'[Movement] ) < 0, BLANK (), SUM ( 'Table'[Movement] ) )
    )
RETURN
    SUMX ( _tab, [sMovement] )

In Matrix Visual - Totals to only sum values greater than 0(Updated).JPG

Best Regards
Community Support Team _ Rena Ruan
If this post helps, then please consider Accept it as the solution to help the other members find it more.

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!

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