Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
hello all,
I'm struggeling with writing the code for a calculated column that sums a column based on another value in each row. As i can't explain this very well in words, I made an example:
| # | Date & Time | Weight | Category | Result |
| 1 | 28-7 8:00 | 10 | A | 10 |
| 2 | 29-7 10:00 | 20 | A | 30 |
| 3 | 29-7 12:00 | 30 | B | 30 |
| 4 | 31-7 15:00 | 50 | B | 120 |
| 5 | 30-7 12:00 | 40 | B | 70 |
I wanted to write something for the result column. This column should sum all the weights of the same category before that moment. In the case of entry #4, it should sum all the weights of entries of category B on or before 31-7 15:00,. which in this example results in 30+40+50.
I have tried some functions as DATAADD and SUMX etc, but couldn't figure it out. I'm hoping someone here can help me!
Solved! Go to Solution.
Hi @Anonymous ,
Make sure that the COlumn is marked as Date- Time in Power Query
Create a Calculated Column
Column =
CALCULATE (
SUM ( 'Table (2)'[Weight] ),
FILTER (
'Table (2)',
'Table (2)'[Date & Time]
<= EARLIER ( 'Table (2)'[Date & Time] )
&& 'Table (2)'[Category]
= EARLIER ( 'Table (2)'[Category] )
)
)
Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)
Hi @Anonymous ,
You can try a measure too.
Measur =
CALCULATE (
SUM ( 'Table (2)'[Weight] ),
FILTER (
ALL ( 'Table (2)' ),
'Table (2)'[Date & Time]
<= MAX ( 'Table (2)'[Date & Time] )
&& 'Table (2)'[Category]
= MAX ( 'Table (2)'[Category] )
)
)
Regards,
Harsh Nathani
Hi @Anonymous Try this measure.
Hi @Anonymous ,
Make sure that the COlumn is marked as Date- Time in Power Query
Create a Calculated Column
Column =
CALCULATE (
SUM ( 'Table (2)'[Weight] ),
FILTER (
'Table (2)',
'Table (2)'[Date & Time]
<= EARLIER ( 'Table (2)'[Date & Time] )
&& 'Table (2)'[Category]
= EARLIER ( 'Table (2)'[Category] )
)
)
Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)
yes this works, thank you very much!
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 20 | |
| 10 | |
| 9 | |
| 4 | |
| 4 |
| User | Count |
|---|---|
| 33 | |
| 31 | |
| 19 | |
| 12 | |
| 10 |