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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
Super User
Super User


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


@ 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!:
The Definitive Guide to Power Query (M)

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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