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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! 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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.