cancel
Showing results for
Did you mean:  Helper I

## Cumulative Emission with Filter condition

Hi Community,

Data PowerBI File

I want to create a measure that can calculate emission up till Forecast value is "N".  I  am trying with following measure but I am still getting values where forecast is "Y".  so, my goal is create  measure that calculate cummulative total up till  Forecast value is "N" and rest is blank.    I guess it is happenig becasue of ALL.

Actual Cumulative Emissions =
VAR _table = FILTER ( ALLSELECTED(data), data[Date] <= MAX( data[Date])&&data[Forecast]="N")
VAR _cumulative_before_forecast = CALCULATE( SUM(data[Emission]) , _table)
Return   _cumulative_before_forecast My expected results should look like this Thankyou in Anticipation

2 ACCEPTED SOLUTIONS  Super User

@sam_hoccane , Try one of the two

Actual Cumulative Emissions =
VAR _max = maxx(filter(allselected(data) ,data[Forecast]="N"), data[Date])
VAR _cumulative_before_forecast = CALCULATE( SUM(data[Emission]) , FILTER ( ALLSELECTED(data), data[Date] <= MAX( data[Date]) && data[Date] <=_max && data[Forecast]="N"))
Return _cumulative_before_forecast

Actual Cumulative Emissions =
VAR _max = maxx(filter(allselected(data) ,data[Forecast]="N"), data[Date])
VAR _cumulative_before_forecast = if( max(data[Date]) <=_max ,CALCULATE( SUM(data[Emission]) , FILTER ( ALLSELECTED(data), data[Date] <= MAX( data[Date]) && data[Forecast]="N")), blank())
Return _cumulative_before_forecast

!! Microsoft Fabric !!
Microsoft Power BI Learning Resources, 2023 !!
Learn Power BI - Full Course with Dec-2022, with Window, Index, Offset, 100+ Topics !!
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!  Community Support

Hi @sam_hoccane ,

I have created a simple sample, please refer to my pbix file to see if it help you.

Create a measure.

``````Measure =
VAR _result =
CALCULATE (
SUM ( 'Table'[Emission] ),
FILTER (
ALL ( 'Table' ),
'Table'[date] <= SELECTEDVALUE ( 'Table'[date] )
&& 'Table'[Forecasst] = "N"
)
)
RETURN
IF ( MAX ( 'Table'[Forecasst] ) = "N", _result, BLANK () )
``````

Or a column.

``````Column =
VAR _result =
CALCULATE (
SUM ( 'Table'[Emission] ),
FILTER (
( 'Table' ),
'Table'[date] <= EARLIER ( 'Table'[date] )
&& 'Table'[Forecasst] = "N"
)
)
RETURN
IF ( 'Table'[Forecasst] = "N", _result, BLANK () )
`````` Best Regards

Community Support Team _ Polly

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

3 REPLIES 3  Helper I

@amitchandak Thank you. It wokred .  Community Support

Hi @sam_hoccane ,

I have created a simple sample, please refer to my pbix file to see if it help you.

Create a measure.

``````Measure =
VAR _result =
CALCULATE (
SUM ( 'Table'[Emission] ),
FILTER (
ALL ( 'Table' ),
'Table'[date] <= SELECTEDVALUE ( 'Table'[date] )
&& 'Table'[Forecasst] = "N"
)
)
RETURN
IF ( MAX ( 'Table'[Forecasst] ) = "N", _result, BLANK () )
``````

Or a column.

``````Column =
VAR _result =
CALCULATE (
SUM ( 'Table'[Emission] ),
FILTER (
( 'Table' ),
'Table'[date] <= EARLIER ( 'Table'[date] )
&& 'Table'[Forecasst] = "N"
)
)
RETURN
IF ( 'Table'[Forecasst] = "N", _result, BLANK () )
`````` Best Regards

Community Support Team _ Polly

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

@sam_hoccane , Try one of the two

Actual Cumulative Emissions =
VAR _max = maxx(filter(allselected(data) ,data[Forecast]="N"), data[Date])
VAR _cumulative_before_forecast = CALCULATE( SUM(data[Emission]) , FILTER ( ALLSELECTED(data), data[Date] <= MAX( data[Date]) && data[Date] <=_max && data[Forecast]="N"))
Return _cumulative_before_forecast

Actual Cumulative Emissions =
VAR _max = maxx(filter(allselected(data) ,data[Forecast]="N"), data[Date])
VAR _cumulative_before_forecast = if( max(data[Date]) <=_max ,CALCULATE( SUM(data[Emission]) , FILTER ( ALLSELECTED(data), data[Date] <= MAX( data[Date]) && data[Forecast]="N")), blank())
Return _cumulative_before_forecast

!! Microsoft Fabric !!
Microsoft Power BI Learning Resources, 2023 !!
Learn Power BI - Full Course with Dec-2022, with Window, Index, Offset, 100+ Topics !!
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!  