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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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