cancel
Showing results for
Did you mean:  Post Prodigy

## How to return a value that precedes the maximum with a measure

Hi all

How can I have returned a value that precedes the maximum from the column called demand?

For example: The max demand is December with 450 and its capacity is 282, so how can I have in a measure returned 195 and also seprately in another measure its capacity 293?

I already have the max demand measure and its respective capacity with the below measures:

``````Max demand =
MAXX(
VALUES(demand[Date]),
[Production]
)``````

``````Capacity of max demand =
CALCULATE (
SUM ( demand[Capacity] ),
TOPN ( 1, ALLSELECTED (demand[Date] ), [Production], DESC )
)``````

Thanks!

2 ACCEPTED SOLUTIONS  Community Champion

Hi @o59393 If this post helps, please consider accepting it as the solution to help the other members find it more quickly.  Super User

Here is one way to get the demand prior to the max demand.  You can adapt the approach for the capacity value.  Just change the SUM in the return to use the Capacity column instead.

Prev Demand =
VAR summary =
SUMMARIZE ( demand, demand[Date], demand[Demand] )
VAR dateofmaxdemand =
MAXX ( TOPN ( 1summary, demand[Demand], DESC ), demand[Date] )
RETURN
CALCULATE (
SUM ( demand[Demand] ),
demand[Date] = EDATE ( dateofmaxdemand-1 )
) Pat

Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

9 REPLIES 9  Super User

Here is one way to get the demand prior to the max demand.  You can adapt the approach for the capacity value.  Just change the SUM in the return to use the Capacity column instead.

Prev Demand =
VAR summary =
SUMMARIZE ( demand, demand[Date], demand[Demand] )
VAR dateofmaxdemand =
MAXX ( TOPN ( 1summary, demand[Demand], DESC ), demand[Date] )
RETURN
CALCULATE (
SUM ( demand[Demand] ),
demand[Date] = EDATE ( dateofmaxdemand-1 )
) Pat

Did I answer your question? Mark my post as a solution! Kudos are also appreciated!  Post Prodigy

Solved. Getting used to the new icons jeje.

``````Prev capacity =
VAR summary =
SUMMARIZE ( demand, demand[Date], demand[Demand] )
VAR dateofmaxcapacity =
MAXX ( TOPN ( 1, summary, demand[demand], DESC ), demand[Date] )
RETURN
CALCULATE (
SUM ( demand[Capacity] ),
demand[Date] = EDATE ( dateofmaxcapacity, -1 )
)``````

Thanks!  Post Prodigy

Thanks a lot. I am trying to re-applicate with capacity however I'm having some difficulties.

Why demand looks like the icon circled below? We didn't create a measure and it's just a column. If I try with capacity I don't get anything as seen underlined below in red: I also tried the following but didn't get the 293 desired result: How can i make it work?

Thanks!  Community Champion

Hi @o59393 If this post helps, please consider accepting it as the solution to help the other members find it more quickly.  Post Prodigy

Thanks @VahidDM !

You used a comparisson of dates to have returned the demand and capacity.

Thanks!  Community Champion

Hi @o59393

Yes I used the dates to find the precede data.

Is that what you need?  Post Prodigy

Yeap, thanks!  Community Champion

You are welcome!

If my post helps, please consider accepting it as the solution to help the other members find it more quickly.  Post Prodigy

@VahidDM  question

I need to use the measure "Production" within your measure.

I tried the following but see the error: How can I make it work?

Thanks!   