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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
PowerRon
Post Patron
Post Patron

How to get the month with the highest number?

Hi, 

 

I don't know how to solve, maybe someone can help.
This is a part from my FAC_Fraud_Schade table

knip1.jpg

 

And this is the measure I try to create. I want to look 13 months back and from those 13 months I want the highest month value.
So if for the month of September the SUM(Aan klant vergoed) is 50.000 and also the highest of all months, I want the measure to return 50.000.
Actually I want the month with the highest value of 'Aan klant vergoed' - 'Voor klant verhaald'.
But already working with one measure gives me trouble.

 

HighestSalesMonth =
VAR EndDate = MAX('FAC_Fraud_Schade'[Datum])  
VAR StartDate = DATE(YEAR(EndDate) - 1, MONTH(EndDate), DAY(EndDate))  
VAR SalesTable = FILTER('FAC_Fraud_Schade','FAC_Fraud_Schade'[Datum] >= StartDate && 'FAC_Fraud_Schade'[Datum] <= EndDate)
VAR SalesPerMonth =
    SUMMARIZE(SalesTable, 'Date'[Year], 'Date'[Month Name Short],
              "MaxSalesPerMonth", SUM('FAC_Fraud_Schade'[Aan klant vergoed]))  
--VAR MaxSales = MAXX(SalesPerMonth, [MaxSalesPerMonth])
VAR MaxSales = CALCULATE(MAX(SalesPerMonth'MaxSalesPerMonth', ALL(SalesPerMonth)                          
RETURN
    MaxSales

It gives the error here

knip2.jpg
 
PS I want the highest value, so that I can give, by using conditonal formatting, the highest value a color. So if SUM Klant Vergoed is the measure, I want in additional column the value 3.712.000 , being the highest month value of the last 13 months in my dataset

knip2.jpg
I hope someone can help

regards
Ron

@eliasayyy @Jihwan_Kim 
1 ACCEPTED SOLUTION
eliasayyy
Memorable Member
Memorable Member

hmm this look tricky i made a sample dataset

annonymous1999_0-1691570945371.png


and a caleendar tabel

annonymous1999_1-1691570957779.png


first i created the measure for per month - year 

 

Total Amount by month = 

    CALCULATE(SUM('Table'[Amount]),ALLEXCEPT('Date','Date'[Month - Year]))

 


next i made a measure to find the past 13 months 

 

Locate past 13 month = 
VAR _min = EOMONTH(CALCULATE(MAX('Date'[Date]),ALL('Date')),-13)
VAR _max = CALCULATE(MAX('Date'[Date]),ALL('Date'))
RETURN
if( MIN('Date'[Date]) >=_min && MAX('Date'[Date]) <=_max , 1 , 0)

 


next i made a measure to find the maxx inside this window

 

Max Amount = 
VAR _t = 
SUMMARIZE(
    FILTER(
        'Date',[Locate past 13 month] = 1),'Date'[Month - Year],"Amount",[Total Amount by month])
RETURN
MAXX(_t,[Amount])


and if you want the columsn to show last results just use 

MAX Amount = 
VAR MaxValue =
    CALCULATE(
        MAXX(
            FILTER(
                ALL('Table'),
                'Table'[Locate past 13 month] = 1
            ),
            [Total Amount by month]
        )
    )
RETURN
    MaxValue

 


final result

annonymous1999_2-1691571043940.png

 

 

annonymous1999_3-1691571625086.png

 

 

View solution in original post

3 REPLIES 3
PowerRon
Post Patron
Post Patron

Thnx @eliasayyy 
I got it working. Understand what you are doing, but still fin dit hard to find out myself.
The issue her of course is also that you don't want the MAX of the whole dataset, but just the MAX of the last 13 months, while the dataset contains 4 years of data.
Thnx for helping me out

PowerRon
Post Patron
Post Patron

Hi @eliasayyy thnx for the great effort. Somewhere this week, hopefully asap, I will test it on my dataset and then let you know.

eliasayyy
Memorable Member
Memorable Member

hmm this look tricky i made a sample dataset

annonymous1999_0-1691570945371.png


and a caleendar tabel

annonymous1999_1-1691570957779.png


first i created the measure for per month - year 

 

Total Amount by month = 

    CALCULATE(SUM('Table'[Amount]),ALLEXCEPT('Date','Date'[Month - Year]))

 


next i made a measure to find the past 13 months 

 

Locate past 13 month = 
VAR _min = EOMONTH(CALCULATE(MAX('Date'[Date]),ALL('Date')),-13)
VAR _max = CALCULATE(MAX('Date'[Date]),ALL('Date'))
RETURN
if( MIN('Date'[Date]) >=_min && MAX('Date'[Date]) <=_max , 1 , 0)

 


next i made a measure to find the maxx inside this window

 

Max Amount = 
VAR _t = 
SUMMARIZE(
    FILTER(
        'Date',[Locate past 13 month] = 1),'Date'[Month - Year],"Amount",[Total Amount by month])
RETURN
MAXX(_t,[Amount])


and if you want the columsn to show last results just use 

MAX Amount = 
VAR MaxValue =
    CALCULATE(
        MAXX(
            FILTER(
                ALL('Table'),
                'Table'[Locate past 13 month] = 1
            ),
            [Total Amount by month]
        )
    )
RETURN
    MaxValue

 


final result

annonymous1999_2-1691571043940.png

 

 

annonymous1999_3-1691571625086.png

 

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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