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

Calculating total for previous day before the latest filtered day

Hi, 

 

I am trying to find a way to show the total of the latest filtered day and the total the day before. I know how to do this with TODAY and YESTERDAY functions but it seems to be a bit more complicated with dynamically changing dates.

 

I succeeded to get the total of the latest filtered day by using this measure:

 

Total of selected day= CALCULATE(

SUM(Table[value]),

FILTER( ALL(Table), Table[date] = Max(Table[date])))

 

This is the measure I tried to use to get the total of the previous day but it is not working as wanted:

 

Total of selected day= CALCULATE(

SUM(Table[value]),

FILTER( ALL(Table), Table[date] = Max(Table[date])-1))

 

I'm very grateful for every tip. Thanks in advance!

 

Julia

 

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

@Anonymous 

The problem seems to be that the date column is of type Datetime rather than date, with non-zero times. That would be why, when comparing to MAX(Table[Date]) - 1 in the filter operation, the equality doesn't hold. Try this:

Day before  V2 =
CALCULATE (
    SUM ( 'Table'[value] ),
    FILTER (
        'Table',
        DATEVALUE ( 'Table'[date] )
            = DATEVALUE ( MAX ( 'Table'[date] ) - 1 )
    )
)

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

3 REPLIES 3
AlB
Community Champion
Community Champion

@Anonymous 

The problem seems to be that the date column is of type Datetime rather than date, with non-zero times. That would be why, when comparing to MAX(Table[Date]) - 1 in the filter operation, the equality doesn't hold. Try this:

Day before  V2 =
CALCULATE (
    SUM ( 'Table'[value] ),
    FILTER (
        'Table',
        DATEVALUE ( 'Table'[date] )
            = DATEVALUE ( MAX ( 'Table'[date] ) - 1 )
    )
)

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Anonymous
Not applicable

Hi,

 

You can download an example file from here:

https://drive.google.com/file/d/1VIWjztF61R834Vm5IfHo-BlK7crZ89EE/view?usp=sharing 

 

I'm trying to compare the two measures in a line chart. The "Last day" measure is working perfectly while the "Previous day" measure is showing a blank box.

 

Thank you for your help!

 

Julia

AlB
Community Champion
Community Champion

Hi @Anonymous 

Your code looks good. What is it that is not working exactly? Can you show some sample with the expected result and the (erroneous) result you currently get? Or best if you can share the pbix

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

 

 

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!

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.