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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Tarte
New Member

DAX command for MIN MAX in horometer

Hi everyone,

 

I have a table containing meter readings for several machines:

MachineDatehour
A01/07/20241000
A10/07/20241100
A23/07/20241150
B09/07/2024200
B01/08/2024300
B20/08/2024350


I would like a DAX measure that could find me the MAX and MIN of the meters for each month for the different machines:

MachineDatehourMinMonthMaxMonth
A01/07/2024100010001150
A10/07/2024110010001150
A23/07/2024115010001150
B09/07/2024200200200
B05/08/2024300300350
B20/08/2024350300350

 

 

I have tried to do this formula but due to the large number of rows in the starting table I have resource errors displaying the measure:

 

MinMonth =
CALCULATE(
    MIN(hour),
    FILTER(
        ALL(table),
        Machine = MAX(Machine) &&
        YEAR(Date) = YEAR(MAX(Date)) &&
        MONTH(Date) = MONTH(MAX(Date))
    )
)

 

thank you in advance

2 ACCEPTED SOLUTIONS
Greg_Deckler
Community Champion
Community Champion

@Tarte What happens if you ditch the ALL in your filter clause?

 

Calculate = 
    VAR __Machine = MAX( 'Table'[Machine] )
    VAR __Date = MAX( 'Table'[Date] )
    VAR __Result = 
        CALCULATE(
            MAX( 'Table'[hour] ),
            'Table'[Machine] = __Machine, YEAR( 'Table'[Date] ) = YEAR( __Date ), MONTH( 'Table'[Date] ) = MONTH( __Date )
        )
RETURN
    __Result

Also, here is a No CALCULATE approach:

NC = 
    VAR __Machine = MAX( 'Table'[Machine] )
    VAR __Date = MAX( 'Table'[Date] )
    VAR __Table = FILTER( ALLSELECTED( 'Table' ), [Machine] = __Machine && YEAR( [Date] ) = YEAR( __Date ) && MONTH( [Date] ) = MONTH( __Date ) )
    VAR __Result = MAXX( __Table, [hour] )
RETURN
    __Result

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Anonymous
Not applicable

Hi @Tarte 

 

Thanks for the reply from Greg_Deckler.

 

The following measures are for your reference.

MinMonth = CALCULATE(MIN([hour]), ALLEXCEPT('Table', 'Table'[Machine]), MONTH('Table'[Date]) = MONTH(MAX([Date])))
MaxMonth = CALCULATE(MAX([hour]), ALLEXCEPT('Table', 'Table'[Machine]), MONTH('Table'[Date]) = MONTH(MAX([Date])))

 

Output:

vxuxinyimsft_0-1723444784011.png

 

Best Regards,
Yulia Xu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Tarte 

 

Thanks for the reply from Greg_Deckler.

 

The following measures are for your reference.

MinMonth = CALCULATE(MIN([hour]), ALLEXCEPT('Table', 'Table'[Machine]), MONTH('Table'[Date]) = MONTH(MAX([Date])))
MaxMonth = CALCULATE(MAX([hour]), ALLEXCEPT('Table', 'Table'[Machine]), MONTH('Table'[Date]) = MONTH(MAX([Date])))

 

Output:

vxuxinyimsft_0-1723444784011.png

 

Best Regards,
Yulia Xu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Community Champion
Community Champion

@Tarte What happens if you ditch the ALL in your filter clause?

 

Calculate = 
    VAR __Machine = MAX( 'Table'[Machine] )
    VAR __Date = MAX( 'Table'[Date] )
    VAR __Result = 
        CALCULATE(
            MAX( 'Table'[hour] ),
            'Table'[Machine] = __Machine, YEAR( 'Table'[Date] ) = YEAR( __Date ), MONTH( 'Table'[Date] ) = MONTH( __Date )
        )
RETURN
    __Result

Also, here is a No CALCULATE approach:

NC = 
    VAR __Machine = MAX( 'Table'[Machine] )
    VAR __Date = MAX( 'Table'[Date] )
    VAR __Table = FILTER( ALLSELECTED( 'Table' ), [Machine] = __Machine && YEAR( [Date] ) = YEAR( __Date ) && MONTH( [Date] ) = MONTH( __Date ) )
    VAR __Result = MAXX( __Table, [hour] )
RETURN
    __Result

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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