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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Create New Measure using Top 3 Highest Values of Another Measure Falling Within Specific Timeframe

Need to create Measure X that sums the top three values, occuring within the last 3 months, of Measure Y (that will filter down and or up timewise (wkly, mnthly, yrly). Simply, Measure Y is an average calc measure summing the 3 values found in Measure X to be divided by Related (count*hours)...[Measure X]/(Related(Table.Count)*Related(Table.Hours)...but not so simply as I am not figuring out how to create Measure X.

 

9 REPLIES 9
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

Is your issue solved now?If not,could you pls check my last reply?

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

 

Anonymous
Not applicable

Switching up original post a bit...MONTH column and COUNT column. I want to create a new measure for TREND column to calculate up to 3 month moving average of COUNT for each future month ignoring any values less than or more than 18% of the prior months' value.

 

Below is what I am trying to accomplish. 

N823198_0-1626817043149.png

 

 

 

 

 

Anonymous
Not applicable

Correction...

N823198_0-1626817902795.png

 

Hi @Anonymous ,

 

How to check whether the prior months' variance is over 18%+-?Can you show me the logic or calculation?

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

 

Anonymous
Not applicable

For May TREND...use March and April counts only as Feburary is outside variance

April - March 598/638 for a variance of 6%

April - February 24/638 for a variance of 96%

 

For June TREND...use May count only as April and March variance is greater than 18%

May - April = 638/793 for a variance of 20%

May - March = 598/793 for a variance of 25%

Hi  @Anonymous ,

 

Sorry for the late reply.

Do you wanna to calculate the data whose variance is below 18%?

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Anonymous
Not applicable

Yes, but only up to the prior three months and if each prior month is over 18%, accept the last prior month's count.

Hi @Anonymous ,

 

Create 2 columns as below:

Trend =
VAR _count =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            'Table',
            'Table'[MonthNo]
                <= EARLIER ( 'Table'[MonthNo] ) - 1
                && 'Table'[MonthNo]
                    >= EARLIER ( 'Table'[MonthNo] ) - 3
        )
    )
VAR _previous =
    CALCULATE (
        MAX ( 'Table'[Count] ),
        FILTER ( 'Table', 'Table'[MonthNo] = EARLIER ( 'Table'[MonthNo] ) - 1 )
    )
VAR _previous_1 =
    CALCULATE (
        MAX ( 'Table'[Count] ),
        FILTER ( 'Table', 'Table'[MonthNo] = EARLIER ( 'Table'[MonthNo] ) - 2 )
    )
VAR _previous_2 =
    CALCULATE (
        MAX ( 'Table'[Count] ),
        FILTER ( 'Table', 'Table'[MonthNo] = EARLIER ( 'Table'[MonthNo] ) - 3 )
    )
RETURN
    IF (
        _previous = BLANK (),
        'Table'[Count],
        IF (
            _previous_1 = BLANK (),
            _previous,
            IF (
                _previous_2 = BLANK (),
                DIVIDE ( _previous + _previous_1, 2 ),
                IF (
                    ABS ( DIVIDE ( _previous_1, _previous ) - 1 ) < 0.18
                        && ABS ( DIVIDE ( _previous_2, _previous ) - 1 ) < 0.18,
                    DIVIDE ( _previous_1 + _previous_2, 2 ),
                    IF (
                        ABS ( DIVIDE ( _previous_1, _previous ) - 1 ) > 0.18
                            && ABS ( DIVIDE ( _previous_2, _previous ) - 1 ) > 0.18,
                        _previous,
                        IF (
                            ABS ( DIVIDE ( _previous_1, _previous ) - 1 ) < 0.18
                                && ABS ( DIVIDE ( _previous_2, _previous ) - 1 ) > 0.18,
                            DIVIDE ( _previous_1 + _previous, 2 ),
                            IF (
                                ABS ( DIVIDE ( _previous_1, _previous ) - 1 ) > 0.18
                                    && ABS ( DIVIDE ( _previous_2, _previous ) - 1 ) < 0.18,
                                DIVIDE ( _previous_2 + _previous, 2 )
                            )
                        )
                    )
                )
            )
        )
    )
% of trend to count = DIVIDE('Table'[Trend],'Table'[Count])

And you will see:

vkellymsft_0-1628048602161.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

Could you pls provide some sample data with expected output for test?

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.