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
danyeungw
Helper II
Helper II

How to get Max and Min Amount by Month

I need to find the max and the min amount in the month for the whole year. I created some data as examples. I need to get the amounts in column 4. Can you please help? Thanks.

 

Year MonthDateAmount  
2022-088/21/2022$393.91$703.76Max in August
2022-088/23/2022$18.32$18.32Min in August
2022-088/25/2022$468.14  
2022-088/27/2022$128.13  
2022-088/29/2022$703.76  
2022-088/31/2022$653.54  
2022-099/1/2022$836.01$836.01Max in September
2022-099/2/2022$400.74$73.97Min in September
2022-099/6/2022$117.92  
2022-099/7/2022$110.67  
2022-099/8/2022$772.33  
2022-099/9/2022$457.63  
2022-099/12/2022$429.05  
2022-099/13/2022$334.74  
2022-099/14/2022$607.19  
2022-099/15/2022$73.97  
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @danyeungw ,

I updated the sample pbix file(see the attachment) base on your latest info, please check if that is what you want...

Sum of Amount = SUM('Table'[Amount]) 
Min = MINX(GROUPBY(ALLSELECTED('Table'),'Table'[Year],'Table'[Month],'Table'[Day]),[Sum of Amount])
Max = MAXX(GROUPBY(ALLSELECTED('Table'),'Table'[Year],'Table'[Month],'Table'[Day]),[Sum of Amount])

yingyinr_0-1665968462264.png

Best Regards

View solution in original post

10 REPLIES 10
Anonymous
Not applicable

Hi @danyeungw ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can create two measures as below to get it:

Max =
CALCULATE (
    MAX ( 'Table'[Amount] ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[Year Month] = SELECTEDVALUE ( 'Table'[Year Month] )
    )
)
Min =
CALCULATE (
    MIN ( 'Table'[Amount] ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[Year Month] = SELECTEDVALUE ( 'Table'[Year Month] )
    )
)

 yingyinr_0-1665647014749.png

Best Regards

Hi @Anonymous ,

Your code work perfect for one transaction per day. How can I get the min and max per day with multiple transaction for each day? Thanks.

 

Anonymous
Not applicable

Hi @danyeungw ,

You can create two measures as below to get it, please find the details in the attachment.

Min = 
CALCULATE (
    MIN ( 'Table'[Amount] ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[Year] = SELECTEDVALUE ( 'Table'[Year] )
            && 'Table'[Month] = SELECTEDVALUE ( 'Table'[Month] )
            && 'Table'[Day] = SELECTEDVALUE ( 'Table'[Day] )
    )
)
Max = 
CALCULATE (
    MAX ( 'Table'[Amount] ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[Year] = SELECTEDVALUE ( 'Table'[Year] )
            && 'Table'[Month] = SELECTEDVALUE ( 'Table'[Month] )
            && 'Table'[Day] = SELECTEDVALUE ( 'Table'[Day] )
    )
)

yingyinr_1-1665715932487.png

Best Regards

Thanks so much @Anonymous. It was my false again that I didn't explane in detail. I am looking for the min and max of the sum for each day. 

YearMonthDay  Amount  Sum for each Day  Min   Max 
      $  1,517.11 $  2,713.94
2022August21 $           11.20   
2022August21 $           87.29   
2022August21 $         922.22   
2022August21 $         130.95 $                   1,151.66  
2022August23 $         927.71   
2022August23 $         248.29   
2022August23 $         293.22   
2022August23 $         844.01 $                   2,313.22  
2022August25 $         591.88   
2022August25 $         964.07   
2022August25 $           81.85   
2022August25 $         826.76 $                   2,464.55  
2022August27 $         992.91   
2022August27 $         787.31   
2022August27 $         933.72 $                   2,713.94  
2022August29 $         334.67   
2022August29 $         778.57   
2022August29 $         678.65   
2022August29 $         500.31 $                   2,292.20  
2022August31 $         101.28   
2022August31 $         473.95   
2022August31 $         941.87 $                   1,517.11  

Correction: Min is 1151.60

Anonymous
Not applicable

Hi @danyeungw ,

I updated the sample pbix file(see the attachment) base on your latest info, please check if that is what you want...

Sum of Amount = SUM('Table'[Amount]) 
Min = MINX(GROUPBY(ALLSELECTED('Table'),'Table'[Year],'Table'[Month],'Table'[Day]),[Sum of Amount])
Max = MAXX(GROUPBY(ALLSELECTED('Table'),'Table'[Year],'Table'[Month],'Table'[Day]),[Sum of Amount])

yingyinr_0-1665968462264.png

Best Regards

@Anonymous Thank you so much for your patience. It works great. 

 

Thanks @Anonymous and @Shaurya. Acutally the date columns are from the date hierarchy. Sorry I example was misleading. How do I concatinate the Year and Month? I tried to use concatinate, but it seems it can only concatinate the Measure. Here is the table.

YearMonthDayAmount
2022August21393.91
2022August2318.32
2022August25468.14
2022August27128.13
2022August29703.76
2022August31653.54
2022September1836.01
2022September2400.74
2022September6117.92
2022September7110.67
2022September8772.33
2022September9457.63
2022September12429.05
2022September13334.74
2022September14607.19
2022September1573.97

Hi @danyeungw,

 

You can merge the year and date columns in Power Query, change the data type to Date and then use the formula in my original reply in DAX.

 

M Code after merging and changing the data type:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fZG9DsIwDITfJXNlxXYSNyMSKxMTqjoUqYKlBUE68PbY3ZASlsvPfbFyumFwl3l6uc6dHmu563qcPqqH5bGtxY3d4MgT2c12295FN4QqnBky1n1WwR6Y6nZUCakHDHVf7Dmpz3U/q4hnkFT12b6XIkP8mX+en2VerrNFNaLnBB5bhJ2D9yDNGcnmoECmFrHnQA9JWkRvlBAwtwjLGqJAahK4f5Uy+NhErBDm8CeNdqGRvADmJmK9ibauccYv", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Year", Int64.Type}, {"Month", type text}, {"Day", Int64.Type}, {"Amount", type number}}),
    #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Changed Type1", {{"Year", type text}}, "en-US"),{"Month", "Year"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
    #"Renamed Columns" = Table.RenameColumns(#"Merged Columns",{{"Merged", "Month Year"}}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Renamed Columns",{{"Month Year", type date}})
in
    #"Changed Type2"

 

Did I answer your question? Mark this post as a solution if I did!
Consider taking a look at my blog: Forecast Period - Graphical Comparison

Shaurya
Memorable Member
Memorable Member

Hi @danyeungw,

 

You can use the following formula to create a table with 3 columns: Month, Max Value in that month and Min Value

 

Max and Min = SUMMARIZE('Table','Table'[Month],"Max",MAX('Table'[Amount]),"Min",MIN('Table'[Amount]))

 

Works for you? Mark this post as a solution if it does!
Consider taking a look at my blog: Forecast Period - Graphical Comparison 

 

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.