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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
jonclay
Helper IV
Helper IV

DAX measure not working correctly when two dates are the same

Hi everyone

I'm using the following DAX measure to calculate the latest gift amount per customer:

LatestValue_Nett =
VAR last_date =
    CALCULATE ( MAX ( transaction[dateofpayment] ), transaction[dc1amount] + transaction[dc2amount] + transaction[dc3amount] <> BLANK () )
RETURN
    CALCULATE ( SELECTEDVALUE ( transaction[dc1amount] ), transaction[dateofpayment] = last_date )

This works fine until we have two transactions for the same person on the same day. In these cases nothing is shown (i.e. a blank value is shown). I assume this is because the DAX can't "decide" which transaction is the latest one (all our transactions have a timestamp of 00:00:00).

How can I change the DAX to show the highest value (dc1amount + dc2amount + dc3amount) if there are multiple transactions on the same day?

Many thanks
Jon
1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@jonclay,

 

Try this measure:

 

LatestValue_Nett = 
// calculate total amount for each date/person
VAR vBaseTable =
    ADDCOLUMNS (
        'transaction',
        "@Amount",
            CALCULATE (
                SUM ( 'transaction'[dc1amount] ) + SUM ( 'transaction'[dc2amount] )
                    + SUM ( 'transaction'[dc3amount] )
            )
    )
// calculate max amount for each date/person
VAR vMaxTable =
    ADDCOLUMNS (
        vBaseTable,
        "@MaxAmount",
            VAR vDate = 'transaction'[dateofpayment]
            VAR vPerson = 'transaction'[person]
            RETURN
                MAXX (
                    FILTER (
                        vBaseTable,
                        'transaction'[dateofpayment] = vDate
                            && 'transaction'[person] = vPerson
                    ),
                    [@Amount]
                )
    )
// sum max amount for each date/person
VAR vResult =
    SUMX ( FILTER ( vMaxTable, [@Amount] = [@MaxAmount] ), [@Amount] )
RETURN
    vResult

 

Here's the result using the sample data below:

 

DataInsights_0-1676040727381.png

 

DataInsights_1-1676040745845.png

 





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

Proud to be a Super User!




View solution in original post

2 REPLIES 2
jonclay
Helper IV
Helper IV

Hi @DataInsights 

Thank you so much, that worked perfectly!

Best wishes
Jon

DataInsights
Super User
Super User

@jonclay,

 

Try this measure:

 

LatestValue_Nett = 
// calculate total amount for each date/person
VAR vBaseTable =
    ADDCOLUMNS (
        'transaction',
        "@Amount",
            CALCULATE (
                SUM ( 'transaction'[dc1amount] ) + SUM ( 'transaction'[dc2amount] )
                    + SUM ( 'transaction'[dc3amount] )
            )
    )
// calculate max amount for each date/person
VAR vMaxTable =
    ADDCOLUMNS (
        vBaseTable,
        "@MaxAmount",
            VAR vDate = 'transaction'[dateofpayment]
            VAR vPerson = 'transaction'[person]
            RETURN
                MAXX (
                    FILTER (
                        vBaseTable,
                        'transaction'[dateofpayment] = vDate
                            && 'transaction'[person] = vPerson
                    ),
                    [@Amount]
                )
    )
// sum max amount for each date/person
VAR vResult =
    SUMX ( FILTER ( vMaxTable, [@Amount] = [@MaxAmount] ), [@Amount] )
RETURN
    vResult

 

Here's the result using the sample data below:

 

DataInsights_0-1676040727381.png

 

DataInsights_1-1676040745845.png

 





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

Proud to be a Super User!




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.