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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
cferraz_hemav
Helper I
Helper I

Cummulative sum with reference date in another table

Hi all!

 

I have a nightmare trying to sum the accumulated value

 

What I have:

Table 1

(...) | field_id | (...) | start_date |

 

Table 2

(...) | field_id | info_date | data | 

 

What I need is to have the accumulated_data (sum) from the start_date to the info_date:

Table 2

(...) | field_id | info_date | data | accumulated_data

 

Any idea to the easier/faster way to do it?

 

Thanks!

 

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @cferraz_hemav 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table1:

d1.png

 

Table2:

d2.png

 

There is no relationship between two tables. You may create a measure or a calculated column as below.

Measure:

Accumulated Measure = 
var _fieldid = SELECTEDVALUE(Table2[field_id])
var _infodate = SELECTEDVALUE(Table2[info_date])
var _startdate =
LOOKUPVALUE(Table1[start_date],Table1[field_id],_fieldid)
var result =
CALCULATE(
    SUM(Table2[data]),
    FILTER(
        ALL(Table2),
        Table2[field_id]=_fieldid&&
        Table2[info_date]>=_startdate&&
        Table2[info_date]<=_infodate
    )
)
return
IF(
    ISBLANK(result),
    0,
    result
)

 

Calculated column:

Accumulated Column = 
var _fieldid = Table2[field_id]
var _infodate = Table2[info_date]
var _startdate =
LOOKUPVALUE(Table1[start_date],Table1[field_id],_fieldid)
var result =
CALCULATE(
    SUM(Table2[data]),
    FILTER(
        ALL(Table2),
        Table2[field_id]=_fieldid&&
        Table2[info_date]>=_startdate&&
        Table2[info_date]<=_infodate
    )
)
return
IF(
    ISBLANK(result),
    0,
    result
)

 

Result:

d3.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-alq-msft
Community Support
Community Support

Hi, @cferraz_hemav 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table1:

d1.png

 

Table2:

d2.png

 

There is no relationship between two tables. You may create a measure or a calculated column as below.

Measure:

Accumulated Measure = 
var _fieldid = SELECTEDVALUE(Table2[field_id])
var _infodate = SELECTEDVALUE(Table2[info_date])
var _startdate =
LOOKUPVALUE(Table1[start_date],Table1[field_id],_fieldid)
var result =
CALCULATE(
    SUM(Table2[data]),
    FILTER(
        ALL(Table2),
        Table2[field_id]=_fieldid&&
        Table2[info_date]>=_startdate&&
        Table2[info_date]<=_infodate
    )
)
return
IF(
    ISBLANK(result),
    0,
    result
)

 

Calculated column:

Accumulated Column = 
var _fieldid = Table2[field_id]
var _infodate = Table2[info_date]
var _startdate =
LOOKUPVALUE(Table1[start_date],Table1[field_id],_fieldid)
var result =
CALCULATE(
    SUM(Table2[data]),
    FILTER(
        ALL(Table2),
        Table2[field_id]=_fieldid&&
        Table2[info_date]>=_startdate&&
        Table2[info_date]<=_infodate
    )
)
return
IF(
    ISBLANK(result),
    0,
    result
)

 

Result:

d3.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you very much for your time and fast reply @v-alq-msft !!

amitchandak
Super User
Super User

@cferraz_hemav , Can you share sample data and sample output in table format?

 

refer if this blog can help

https://community.powerbi.com/t5/Community-Blog/Decoding-Direct-Query-in-Power-BI-Part-2-Date-Differ...

for Cummulative  need example data

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Thanks for the fast reply!!

 

Table 1

field_idstart_date
3142401/01/2020
0015606/06/2020

 

Table 2 (in green the wanted one)

field_idinfo_datedataaccumulated_data
3142405/01/2020-21,28-21,28
3142415/01/2020-22,11-43,39
0015605/01/2020-33,050
    

 

hope this example is enough

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.