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

Shape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.

Reply
Oelshamy
Helper I
Helper I

Return the Maximum count accordingfor past 3 years

I have a table called Safety Observations and counting the Safety Observations serial number and trying to return the maximum in each month for the past two years compare it with the current Year and add it in a trend line, as per the below image. 

 

For example, in January looking at the past 2 years - the maximum is in 2023 so it should return 30, meanwhile in February the maximum was in 2022 so I want to return 19. 

 

Oelshamy_1-1717572660719.png

This is the Formula that i have used but its returning the 2024 .

Max Per Year = CALCULATE (COUNT('Safety Observations'[SerialNo]) ,
FILTER ( ALL ( 'Date Dimension' ), 'Date Dimension'[Month] = MAX ( 'Date Dimension'[Month] ) ),
DATESINPERIOD ( 'Date Dimension'[Date].[Date], LAST DATE ( 'Date Dimension'[Date].[Date] ), -2, YEAR )
)

Appreciate your guidance 

1 ACCEPTED SOLUTION
Oelshamy
Helper I
Helper I

I have found the solution for this as below: 

Created a Measure for getting last years: 

_m_MaxLastTwoYears =
CALCULATE(
    MAXX(
        SUMMARIZE(
            FILTER(
                'Safety Observations',
                'Safety Observations'[Created].[Year] IN {YEAR(TODAY()) - 1, YEAR(TODAY()) - 2}
            ),
             'Date Dimension'[MonthYear],
            "MonthlyMax", Count('Safety Observations'[SerialNo])
        ),
        [MonthlyMax]
    )
)
then created a measure to get them for this year: 

_mMaxCurrentYear =
CALCULATE(
    MAXX(
        SUMMARIZE(
            FILTER(
                'Safety Observations',
                'Safety Observations'[Year] = YEAR(TODAY())
            ),
           'Safety Observations'[Created_Month],
            "MonthlyCount", COUNT('Safety Observations'[SerialNo])
        ),
        [MonthlyCount]
    )
)
 
Then created a measure that compares both and returns the best-performing month: 
 
_m_CompareMaxObservations =
IF(
    [_mMaxCurrentYear] > [_m_MaxLastTwoYears],
    [_mMaxCurrentYear],
    [_m_MaxLastTwoYears]
)
 
Oelshamy_0-1718009042302.png

 



 

View solution in original post

5 REPLIES 5
Oelshamy
Helper I
Helper I

I have found the solution for this as below: 

Created a Measure for getting last years: 

_m_MaxLastTwoYears =
CALCULATE(
    MAXX(
        SUMMARIZE(
            FILTER(
                'Safety Observations',
                'Safety Observations'[Created].[Year] IN {YEAR(TODAY()) - 1, YEAR(TODAY()) - 2}
            ),
             'Date Dimension'[MonthYear],
            "MonthlyMax", Count('Safety Observations'[SerialNo])
        ),
        [MonthlyMax]
    )
)
then created a measure to get them for this year: 

_mMaxCurrentYear =
CALCULATE(
    MAXX(
        SUMMARIZE(
            FILTER(
                'Safety Observations',
                'Safety Observations'[Year] = YEAR(TODAY())
            ),
           'Safety Observations'[Created_Month],
            "MonthlyCount", COUNT('Safety Observations'[SerialNo])
        ),
        [MonthlyCount]
    )
)
 
Then created a measure that compares both and returns the best-performing month: 
 
_m_CompareMaxObservations =
IF(
    [_mMaxCurrentYear] > [_m_MaxLastTwoYears],
    [_mMaxCurrentYear],
    [_m_MaxLastTwoYears]
)
 
Oelshamy_0-1718009042302.png

 



 
Joe_Barry
Super User
Super User

Hi @Oelshamy 

 

You could try. It seems to work

Trend line = CALCULATE(MAX(Inc[Incidents]), ALLEXCEPT('Date', 'Date'[Month Name]))

 Joe

Joe_Barry_0-1717590184060.png

 




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

Proud to be a Super User!





Learn about the Star Schema, it will solve many issues in Power BI!

Date tables help! Learn more



LinkedIn
Let's connect on LinkedIn


Dear Joe, Appreciate your response, I am not sure about your formuala but mine worked as below, i wanted to compare this year with the best performing month in 22 and 23 as below. 

 

Oelshamy_0-1717591627314.png

 

Hi,@Oelshamy

 

We are happy to know that the issue has been resolved. We would appreciate it if you would be willing to share the solution with us to facilitate a solution for the same problem. Additionally, this would be beneficial to other community members as well.

Certainly, if there is anything else we can do for you, please do not hesitate to contact us.

 

Looking forward to your reply.

Best Regards,

Leroy Lu

 

Sorry I misunderstood, glad you got it working!




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

Proud to be a Super User!





Learn about the Star Schema, it will solve many issues in Power BI!

Date tables help! Learn more



LinkedIn
Let's connect on LinkedIn


Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.