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
Anonymous
Not applicable

calculate column based on the date value of that row

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 & TimeWeightCategoryResult
128-7 8:0010A10
229-7 10:0020A30
329-7 12:0030B30
431-7 15:0050B120
530-7 12:0040B70

 

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!

1 ACCEPTED SOLUTION
harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

Make sure that the COlumn is marked as Date- Time in Power Query

 

1.jpg

 

 

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] )
    )
)

 

 

1.jpg

 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

View solution in original post

4 REPLIES 4
harshnathani
Community Champion
Community Champion

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

Anonymous
Not applicable

Hi @Anonymous Try this measure.

Res =
VAR dt = SELECTEDVALUE('Table'[Date & Time])
VAR filteredTable = FILTER(ALLEXCEPT('Table', 'Table'[Category]), 'Table'[Date & Time] <= dt)
Return SUMX(filteredTable, 'Table'[Weight])
 
Hope this helps.
 
Please mark this as a solution if it serves the purpose.
Thanks
harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

Make sure that the COlumn is marked as Date- Time in Power Query

 

1.jpg

 

 

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] )
    )
)

 

 

1.jpg

 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Anonymous
Not applicable

yes this works, thank you very much!

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.