Forum Discussion
calculate the accumulated
I created a measurement that averages the amount of rain in a day on a farm, now I would like to do the cumulative calculation, that is, the value of the next line is the sum of the previous lines
Your date_short column was of type text. It needs to be of type date. That is why my first version was failing. It will work if you use this to create that column instead of the LEFT([date], 9) you had:
Date_short = DATEVALUE([date])I have created another version that wil work with the months. Note that I have gotten rid of the date hierarchy (which I would strongly discourage as it can be the hidden cause of many problems) and created a month column. It would be better to create a Year-Month column and better still to use a date table.
teste26/12 V2 = VAR currentDate_ = MAX ( 'coperplan01 pluviometer_monitoring_list'[Date_short] ) VAR dates_ = FILTER ( CALCULATETABLE ( DISTINCT ( 'coperplan01 pluviometer_monitoring_list'[Date_short] ), ALLSELECTED ( 'coperplan01 pluviometer_monitoring_list'[Date_short], 'coperplan01 pluviometer_monitoring_list'[Month] ) ), [Date_short] <= currentDate_ ) RETURN CALCULATE ( SUMX ( dates_, [Chuva Acumulada_] ), ALLSELECTED ( 'coperplan01 pluviometer_monitoring_list'[Date_short], 'coperplan01 pluviometer_monitoring_list'[Month] ) )See it all at work in the attached file (Page 3)
Please accept the solution when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
13 Replies
- AlB
Community Champion
Your date_short column was of type text. It needs to be of type date. That is why my first version was failing. It will work if you use this to create that column instead of the LEFT([date], 9) you had:
Date_short = DATEVALUE([date])I have created another version that wil work with the months. Note that I have gotten rid of the date hierarchy (which I would strongly discourage as it can be the hidden cause of many problems) and created a month column. It would be better to create a Year-Month column and better still to use a date table.
teste26/12 V2 = VAR currentDate_ = MAX ( 'coperplan01 pluviometer_monitoring_list'[Date_short] ) VAR dates_ = FILTER ( CALCULATETABLE ( DISTINCT ( 'coperplan01 pluviometer_monitoring_list'[Date_short] ), ALLSELECTED ( 'coperplan01 pluviometer_monitoring_list'[Date_short], 'coperplan01 pluviometer_monitoring_list'[Month] ) ), [Date_short] <= currentDate_ ) RETURN CALCULATE ( SUMX ( dates_, [Chuva Acumulada_] ), ALLSELECTED ( 'coperplan01 pluviometer_monitoring_list'[Date_short], 'coperplan01 pluviometer_monitoring_list'[Month] ) )See it all at work in the attached file (Page 3)
Please accept the solution when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
- gelsonwj
Helper I
You are my hero
- AlB
Community Champion
Hi gelsonwj
Can you share the code of your current measure? It can probably be modified slightly to get to the cumulative.
Please accept the solution when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
- gelsonwj
Helper I
Ok
- gelsonwj
Helper I
this doesn't work for me, because the SUM() function only accepts a table, and in my case I have a measure that calculates the accumulated rain