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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Michael92
Frequent Visitor

DAX calculation

Hello all,
I need to calculate the Stock - Request difference in the Matrix table. I always see only 3 days, yesterday, today and tomorrow. I need to calculate the current stock situation. I need to count requests and subtract it from the current situation in stock. For example, for Material M001... for 12.11.2024 it will be 80-60 =20,

for 13.11.2024 it will be 60+100-80 = -80

for 14.11.2024 it will be 60+100+20-80 = -100.
Is it possible to do this calculation in DAX and use it in matrix?

 

Michael92_0-1731489067514.png

 

Thank you

1 ACCEPTED SOLUTION

Hello,

 

thanks for your feedback. It gave me zero values ​​everywhere.

But meanwhile i found a solution. This works for me:

Difference =
    CALCULATE(
SUM('Table'[Stock]) - SUM('Table'[Request]),FILTER(ALL(Date_table), Date_table[Date]<= MAX(Date_table[Date])))

View solution in original post

2 REPLIES 2
shafiz_p
Super User
Super User

Hi @Michael92  Try below code:

Diff = 
VAR CurrentDate = MAX('Table'[Date])
VAR StockOnDate = 
    CALCULATE(
        [Stock'],
        'Table'[Date] = CurrentDate
    )
VAR RequestsUpToDate = 
    CALCULATE(
        [Request'],
        'Table'[Date] <= CurrentDate
    )
RETURN
    StockOnDate - RequestsUpToDate

Where :

[Stock'] = SUM('Table'[Stock])
[Request'] = SUM('Table'[Request])

 

Output:

shafiz_p_0-1731491550730.png

 

Considering Dataset:

shafiz_p_1-1731491582072.png

 

 

Hope this helps!!

If this solved your problem, please accept it as a solution and a kudos!!

 

 

Best Regards,
Shahariar Hafiz

Hello,

 

thanks for your feedback. It gave me zero values ​​everywhere.

But meanwhile i found a solution. This works for me:

Difference =
    CALCULATE(
SUM('Table'[Stock]) - SUM('Table'[Request]),FILTER(ALL(Date_table), Date_table[Date]<= MAX(Date_table[Date])))

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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