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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

DAX: get sum of a value, x days before minimum user defined date

Hi all. 

 

I have the following scenario: 

 

1) Users selects a daterange (lets say, 7jan-8jan)

2) I want to dynamically extract the sum of another column, two days before the minimum filter value (5jan-6jan)

 

For me, the hard part is that the context "hides" the data i want to sum (5jan-6jan).

 

I have tried A LOT of stuff, with no succes. The following example is one of the (better) attempts. 


All help much appriciated!

 

 

 

two days before = 

VAR _mindate = calculate(MIN(testdata[sessiondate]),FILTER(testdata, testdata[amount]>0)

RETURN

CALCULATE(sum(testdata[amount]),
filter(ALLEXCEPT(testdata,'Date'[date]),testdata[sessiondate]=_mindate))
 
1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @Anonymous

 

It seems like you have a Date table already. If you're using the Date table in your slicer,  try this:

 

two days before =
VAR _mindate =
    MIN ( 'Date'[date] )
RETURN
    CALCULATE (
        SUM ( testdata[amount] ),
        FILTER (
            ALL ( 'Date' ),
            'Date'[date]=_mindate - 1 || 'Date'[date]=_mindate - 2
        )
    )

 

Code formatted with   www.daxformatter.com

View solution in original post

4 REPLIES 4
AlB
Community Champion
Community Champion

Hi @Anonymous

 

It seems like you have a Date table already. If you're using the Date table in your slicer,  try this:

 

two days before =
VAR _mindate =
    MIN ( 'Date'[date] )
RETURN
    CALCULATE (
        SUM ( testdata[amount] ),
        FILTER (
            ALL ( 'Date' ),
            'Date'[date]=_mindate - 1 || 'Date'[date]=_mindate - 2
        )
    )

 

Code formatted with   www.daxformatter.com

Anonymous
Not applicable

Hi @AlB

 

Works. Thank you so much! 

 

Yes, i have a date table that is connected to my main table. I guess my learning here, is not to forget that Power BI queries on the underlying relational structure. 

 

Your answer is definitely accepted, but ATM i can't accept as i'm getting a "authentication failed". I'll try again tomorrow.

 

- Thanks again!

 

 

AlB
Community Champion
Community Champion

@Anonymous

Cool. Yeah, quite a few features at the site have not been working properly over the last days

AlB
Community Champion
Community Champion

@Anonymous

Seems like the 'mark as solution' feature is working again 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.