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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
andrezmor
Frequent Visitor

Weighet Average Based On Previous Row with additional conditions

I have a table that I am naming “Transaction_TB” where each row corresponds to a transaction for inputs and outputs of coal tonnage in an inventory system, the table has 4 columns

[Rank] = Unique ID that can be used to sort records in chronological order

[Type] = Type of Transaction (IN or OUT)

[Tons] = amount of ton that are being moved, OUT Type transactions are negative

[Quality]= Only Type IN transaction have quality

 

I have calculated the BALANCE_TONS after each transaction which is simply add or subtract IN Type transaction minus OUT Type transactions, no problem with that, however my problem is calculating the BALANCE_QUALITY

** BALANCE_QUALITY has to be calculated as weighted average over the Tons

** Only the Type IN transaction affect the quality, so for Type OUT transactions the Quality is the same as previous transaction.

 

The expected result would be

 

ejemplo.JPG

 

I appreciate your help and suggestion on how to solve the problem.

 

Thanks

 

 

 

 

3 REPLIES 3
ryan_mayu
Super User
Super User

@andrezmor 

how you get the balance qty? could you pls provide more details?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @ryan_mayu 

 

For Rank # 2 it would be:

ejemplo.JPG

For Rank # 3
                Quality is the same as previous BALANCE_QUALITY only BALANCE_TONS is affected.

For Rank # 4

ejemplo 2.JPG

 

 

 

 

Thanks

@andrezmor 

balance_tons = sumx(FILTER('Table','Table'[Type]="IN"&&'Table'[Rank]<=EARLIER('Table'[Rank])),'Table'[Tons])+ sumx(FILTER('Table','Table'[Type]="OUT"&&'Table'[Rank]<=EARLIER('Table'[Rank])),'Table'[Tons])
 
the second column will cause circular reference. Let's see if anyone else can help you on this.




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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