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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Debo1996
Regular Visitor

Create a measure to get sum of values from two columns

I have two tables named:

1. Item Master (This has item name, unique code, opening amount and opening quantity at a fixed date (1-Apr-2022) )

2. Transactions (Item transactions from 1-Apr-2022 to 31-Mar-2023)

 

Sample: 

 

Item Master Table
CodeItem NameOpening QuantityOpening Value
A-001Paint Red5500
A-002Paint Blue3300
A-003Paint Green2200
B-001Brush Small1001000
B-002Brush Medium1222440

 

 

Transaction Table
DateTransaction TypeCodeQuantityRateAmount
01/04/22SaleA-0012105210
01/04/22SaleA-0022105210
01/04/22SaleA-0032105210
04/04/22PurchaseB-00151050
04/04/22PurchaseB-002520100
10/04/22SaleB-0015011550
10/04/22SaleB-0024022880
10/04/22SaleA-0011105105

 

Now I want to create a measure to get closing balance as of any date for all stock items. 

What will be the DAX formula for such a measure? (Assume date table exists with name Date Table)

 

Thank you!!

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Debo1996 

please try

Closing Quantity =
MAX ( 'Item Master'[Opening Quantity] )
+ CALCULATE (
SUMX (
Transaction,
IF (
Transaction[Transaction Type] = "Sale",
Transaction[Transaction Quantity],
- Transaction[Transaction Quantity]
)
),
Transaction[Date] <= MAX ( Transaction[Date] )
)

View solution in original post

1 REPLY 1
tamerj1
Super User
Super User

Hi @Debo1996 

please try

Closing Quantity =
MAX ( 'Item Master'[Opening Quantity] )
+ CALCULATE (
SUMX (
Transaction,
IF (
Transaction[Transaction Type] = "Sale",
Transaction[Transaction Quantity],
- Transaction[Transaction Quantity]
)
),
Transaction[Date] <= MAX ( Transaction[Date] )
)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.