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
Buckeye_Amy
Frequent Visitor

DAX Sumif Filtered Amount Between Date

Hi!

I am a novice DAX user struggling to write the equivalent of SUMIF in Excel in DAX. I am currently working with DAX in the Excel Data Model environment. The dataset am I working with is contributions and distributions from/to multiple investors in multiple investments. The data table includes both contributions and distributions. The goal is to ultimately calculate the long-term/short-term nature of gain and loss per investor per investment on a first-in first-out basis.

 

I am stuck on calculating the long-term contributions related to a particular(singular) distribution. Long-term contributions are those contributions the occured 366 days before the date of distribution. For example, the long-term contributions for Investor LP0001 in InvA related to the distribution on 2/9/2021 (row 4 below) equals $500,000 ($100,000 contribution on 5/14/209 and $400,000 contribution on 6/7/2019).

 

I have created a long-term holding date calculated field, but I'm not sure that's even necessary. I'm open to all options.

 

Thank you in advance! 🙂

 

Link to Sample Data

 

Buckeye_Amy_0-1690558500664.png

 

1 ACCEPTED SOLUTION
Martin_D
Super User
Super User

Hi @Buckeye_Amy ,

The equivalent of Excel SUMIF in DAX is a combination of SUMX and FILTER. The following measure solves your requirement based on the table structure provided on sheet "Data" in your Excel file:

 

 

Long Term Contributions = 
VAR _LongtermContributionsDaysOffset = 366

VAR _AmountOfLongTermContributions =
    ADDCOLUMNS (
        CALCULATETABLE (
            SUMMARIZECOLUMNS (
                'Data'[InvestorNo],
                'Data'[Investment],
                'Data'[InvestTranDate]
            ),
            KEEPFILTERS ( 'Data'[InvestTranType] = "Distribution" )
        ),
        "@AmountOfLongTermContributions",
        SUMX (
            FILTER (
                ALL ( 'Data' ),
                'Data'[InvestorNo] = EARLIER ( [InvestorNo] ) &&
                'Data'[Investment] = EARLIER ( [Investment] ) &&
                'Data'[InvestTranDate] <= EARLIER ( [InvestTranDate] ) - _LongtermContributionsDaysOffset + 1 &&
                'Data'[InvestTranType] = "Contribution"
            ),
            [TranAmount]
        )
    )
RETURN
SUMX ( _AmountOfLongTermContributions, [@AmountOfLongTermContributions] )

 

 

The part replacing the SUMIF is:

 

SUMX (
    FILTER (
        ALL ( 'Data' ),
        'Data'[InvestorNo] = EARLIER ( [InvestorNo] ) &&
        'Data'[Investment] = EARLIER ( [Investment] ) &&
        'Data'[InvestTranDate] <= EARLIER ( [InvestTranDate] ) - _LongtermContributionsDaysOffset + 1 &&

        'Data'[InvestTranType] = "Contribution"

    ),
    [TranAmount]
)

 

The result looks like (. and , will switch based on locale settings):

Martin_D_0-1690726938128.png

 

You can download the file here: sumif.pbix

BR

Martin

github.pnglinkedin.png

View solution in original post

3 REPLIES 3
Buckeye_Amy
Frequent Visitor

Martin: Thank you for your help! This solution worked!

Martin_D
Super User
Super User

Hi @Buckeye_Amy ,

The equivalent of Excel SUMIF in DAX is a combination of SUMX and FILTER. The following measure solves your requirement based on the table structure provided on sheet "Data" in your Excel file:

 

 

Long Term Contributions = 
VAR _LongtermContributionsDaysOffset = 366

VAR _AmountOfLongTermContributions =
    ADDCOLUMNS (
        CALCULATETABLE (
            SUMMARIZECOLUMNS (
                'Data'[InvestorNo],
                'Data'[Investment],
                'Data'[InvestTranDate]
            ),
            KEEPFILTERS ( 'Data'[InvestTranType] = "Distribution" )
        ),
        "@AmountOfLongTermContributions",
        SUMX (
            FILTER (
                ALL ( 'Data' ),
                'Data'[InvestorNo] = EARLIER ( [InvestorNo] ) &&
                'Data'[Investment] = EARLIER ( [Investment] ) &&
                'Data'[InvestTranDate] <= EARLIER ( [InvestTranDate] ) - _LongtermContributionsDaysOffset + 1 &&
                'Data'[InvestTranType] = "Contribution"
            ),
            [TranAmount]
        )
    )
RETURN
SUMX ( _AmountOfLongTermContributions, [@AmountOfLongTermContributions] )

 

 

The part replacing the SUMIF is:

 

SUMX (
    FILTER (
        ALL ( 'Data' ),
        'Data'[InvestorNo] = EARLIER ( [InvestorNo] ) &&
        'Data'[Investment] = EARLIER ( [Investment] ) &&
        'Data'[InvestTranDate] <= EARLIER ( [InvestTranDate] ) - _LongtermContributionsDaysOffset + 1 &&

        'Data'[InvestTranType] = "Contribution"

    ),
    [TranAmount]
)

 

The result looks like (. and , will switch based on locale settings):

Martin_D_0-1690726938128.png

 

You can download the file here: sumif.pbix

BR

Martin

github.pnglinkedin.png

Hi Martin,

 

Quick follow-up. It appears that this solution may be causing circular dependency issues in subsequent calucated columns. Are there any changes we can make to the DAX to prevent circular issues?

 

Thanks so much!

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.