cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
o59393
Post Prodigy
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:

 

o59393_1-1635114743573.png

 

 

 

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 )
)

 

Pbix is https://1drv.ms/u/s!ApgeWwGTKtFdh2jsDOgDc0mJVwJa?e=MKqjBa

 

Thanks!

2 ACCEPTED SOLUTIONS
VahidDM
Community Champion
Community Champion

Hi @o59393 

 

Please download this file:  https://gofile.io/d/4TBWuq

 

VahidDM_1-1635118776154.png

 

 

 

 

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

 

Appreciate your Kudos!!

 

View solution in original post

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

 

mahoneypat_0-1635118821517.png

 

Pat





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

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

9 REPLIES 9
mahoneypat
Super User
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 )
    )

 

mahoneypat_0-1635118821517.png

 

Pat





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

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

Hi @mahoneypat 

 

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!

Hi @mahoneypat 

 

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.

 

o59393_0-1635119364101.png

 

If I try with capacity I don't get anything as seen underlined below in red:

 

o59393_1-1635119465261.png

 

I also tried the following but didn't get the 293 desired result:

 

o59393_3-1635119668070.png

 

 

How can i make it work?

 

Thanks!

VahidDM
Community Champion
Community Champion

Hi @o59393 

 

Please download this file:  https://gofile.io/d/4TBWuq

 

VahidDM_1-1635118776154.png

 

 

 

 

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

 

Appreciate your Kudos!!

 

View solution in original post

Thanks @VahidDM !

 

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

 

Thanks!

VahidDM
Community Champion
Community Champion

Hi @o59393 

 

Yes I used the dates to find the precede data.

Is that what you need? 

 

Appreciate your Kudos!!

 

Yeap, thanks!

VahidDM
Community Champion
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.

Appreciate your Kudos!!

@VahidDM  question

 

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

 

I tried the following but see the error:

 

o59393_1-1635121210116.png

 

How can I make it work?

 

Thanks!

 

 

  

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

November Power BI Update 768x460.png

Check it Out!

Click here to read more about the November 2021 Updates!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.