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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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

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

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

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


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

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

 

Thanks @VahidDM !

 

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

 

Thanks!

Hi @o59393 

 

Yes I used the dates to find the precede data.

Is that what you need? 

 

Appreciate your Kudos!!

 

Yeap, thanks!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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