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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Sarah_Jolliffe
New Member

Sum / divide values between dates

Hoping someone can help. I've got stuck trying to do time-based analysis on the following table concerning carbon savings. An example of the table is below and also the closest DAX code used in a measure. The measure is not summing correctly.

 

[Carbon initiatives]

Initiaitve nameStart dateEnd DateDaily tCO2e SavedTotal tCO2e Saved
Carbon 130/6/1831/12/200.00070990.6
Carbon 217/7/1817/10/180.168129715.5
Carbon 31/1/1731/12/192.23804042,448.4
Carbon 422/2/1920/5/200.142583564.6

 

[Measure]

tCO2e saved = VAR tmpCalendar = ADDCOLUMNS('Datetable',"Month",MONTH([Date]),"Year",YEAR([Date]),"MonthYear",VALUE(YEAR([Date])))
VAR tmpCarbon = ADDCOLUMNS('Carbon_Initiatives',"MonthYearBegin",VALUE(YEAR([Start date])),
                                      "MonthYearEnd",VALUE(YEAR([End date])))
VAR tmpTable =
SELECTCOLUMNS(
    FILTER(
        GENERATE(
            tmpCarbon,
            SUMMARIZE(tmpCalendar,[Year],[Month],[MonthYear])
        ),
        [MonthYear] >= [MonthYearBegin] &&
        [MonthYear] <= [MonthYearEnd]
    ),
    "tCO2e",Carbon_Initiatives[Daily tCO2e Saved]
)
RETURN SUmx(tmpTable,[Total tCO2e])
 
[PBI model]
YeartCO2e saved
2017649927.39
2018793721.03
2019483959.38

 

Any help much appreciated

2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion


Not 100% sure what you are going for but take a look at these two Quick Measures as I think you want something like them.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364
https://community.powerbi.com/t5/Quick-Measures-Gallery/Periodic-Billing/m-p/409365



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Spoiler
Cheers for the quick reply, I did come across those 2 posts and plagerised the code just inserted my table refs but that is chucking out duff figures. this is what i did;



tCO2e saved = VAR tmpCalendar = ADDCOLUMNS('Dates2',"Month",MONTH([Date]),"Year",YEAR([Date]),"MonthYear",VALUE(YEAR([Date])))
VAR tmpcarbon = ADDCOLUMNS('Carbon_Initiatives',"MonthYearBegin",VALUE(YEAR(Carbon_Initiatives[Start date])),
                                      "MonthYearEnd",VALUE(YEAR(Carbon_Initiatives[End date])))
VAR tmpTable =
SELECTCOLUMNS(
    FILTER(
        GENERATE(
            tmpcarbon,
            SUMMARIZE(tmpCalendar,[Year],[Month],[MonthYear])
        ),
        [MonthYear] >= [MonthYearBegin] &&
        [MonthYear] <= [MonthYearEnd]
    ),
    "CI_UID",[CI Ref number],
    "Year",[Year],
    "Month",[Month],
    "tCO2e",Carbon_Initiatives[Daily tCO2e Saved]
)
RETURN SUMX(tmpTable,[tCO2e])



and i now get these results

YeartCO2e Saved
2018629.48
2019708.15
20201.35

should be this

YeartCO2e Saved
20183,450
20194,807
2020909

Ideas?

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.