Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
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!
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 8 | |
| 6 | |
| 5 | |
| 5 | |
| 4 |
| User | Count |
|---|---|
| 25 | |
| 16 | |
| 8 | |
| 7 | |
| 7 |