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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ericOnline
Post Patron
Post Patron

MAX of Multiple Columns? Why is this not working?

I have three tables. I need the MAX timestamp from a column in each table. 

Why does this not work? 

ALL_LastRecord = 
    VAR var1LatestRecord = MAX(table1[timeStamp])
    VAR var2LatestRecord = MAX(table2[timeStamp])
    VAR var3LatestRecord = MAX(table3[timeStamp])
    RETURN
    MAX(var1LatestRecord, var2LatestRecord, var3LatestRecord)

How would I accomplish this in DAX?

(Without merging any tables, adding columns, etc.. I do not want to manipulate the tables to do this. Should be straightforward in DAX.)

Thank you 

2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

You need MC Aggregations:  https://community.powerbi.com/t5/Quick-Measures-Gallery/Multi-Column-Aggregations-MC-Aggregations/m-...

 

 

"I like big aggregations and I cannot lie

You other PBI'ers can't deny"


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

amitchandak
Super User
Super User

@ericOnline 

Try

ALL_LastRecord = 
    VAR var1LatestRecord = MAX(table1[timeStamp])
    VAR var2LatestRecord = MAX(table2[timeStamp])
    VAR var3LatestRecord = MAX(table3[timeStamp])
    RETURN
    MAX(var1LatestRecord, max(var2LatestRecord, var3LatestRecord))

 

 

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@ericOnline 

Try

ALL_LastRecord = 
    VAR var1LatestRecord = MAX(table1[timeStamp])
    VAR var2LatestRecord = MAX(table2[timeStamp])
    VAR var3LatestRecord = MAX(table3[timeStamp])
    RETURN
    MAX(var1LatestRecord, max(var2LatestRecord, var3LatestRecord))

 

 

Greg_Deckler
Super User
Super User

Also, with your code, you could have done:

ALL_LastRecord =
VAR var1LatestRecord = MAX(table1[timeStamp])
VAR var2LatestRecord = MAX(table2[timeStamp])
VAR var3LatestRecord = MAX(table3[timeStamp])
RETURN
MAXX( {var1LatestRecord, var2LatestRecord, var3LatestRecord}, [Value] )


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

You need MC Aggregations:  https://community.powerbi.com/t5/Quick-Measures-Gallery/Multi-Column-Aggregations-MC-Aggregations/m-...

 

 

"I like big aggregations and I cannot lie

You other PBI'ers can't deny"


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Boom! The multiple aggregation approach worked.

 

ALL_LastRecord = 
    CONCATENATE(
        "Last Updated: ",
        VAR varTimestamp1 = SELECTCOLUMNS(table1,"Column",[timestamp])
        VAR varTimestamp2 = SELECTCOLUMNS(table2,"Column",[timestamp])
        VAR varTimestamp3 = SELECTCOLUMNS(table3,"Column",[timestamp])
        VAR tmpTable = UNION(UNION(varTimestamp1,varTimestamp2),varTimestamp3)
        VAR tmpValue = MAXX(tmpTable,[Column])
        RETURN tmpValue
    )

 

Bingo! So did @amitchandak 's approach! (Ended up going with this solution because less code)

 

ALL_LastRecord = 
    CONCATENATE(
        "Last Updated: ",
        VAR varTimestamp1 = MAX(table1[timestamp])
        VAR varTimestamp2 = MAX(table2[timestamp])
        VAR varTimestamp3 = MAX(table3[timestamp])
        RETURN
        MAX(varTimestamp1, MAX(varTimestamp2, varTimestamp3))
    )

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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