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
kylee_anne
Helper II
Helper II

Calculate on reconstructed date not working

Hi Everyone,

 

So this is my code:

Delivered Last 24hrs =
var toddy = MAX('Report Date'[Report Date])
var yesterday = day(toddy)-1
return
CALCULATE(sum('Daily Cement Delivered'[Value])+0,'Daily Cement Usage'[Date]= date(year(toddy),month(toddy),yesterday))
 
Report Date is 11/8/25 so my reconstructed calculate condition is 10/8/25 which should give me as answer 23 tonnes.  But it is actually not filtering at all and summing everything.  
 
Any ideas what I'm missing?  Is it a time thing?

 

1 ACCEPTED SOLUTION
wardy912
Solution Supplier
Solution Supplier

Hi @kylee_anne 

 

 You need to wrap the second part of the CALCULATE statement in a FILTER function to accurately apply row by row filtering. I've also added INT to ensure the date you are using is only using the date if the type is actually datetime. Finally, i've added +0 to deal with any blanks.

 

Delivered Last 24hrs =
VAR toddy = MAX('Report Date'[Report Date])
VAR yesterday = toddy - 1
RETURN
CALCULATE(
    SUM('Daily Cement Delivered'[Value]) + 0,
    FILTER(
        'Daily Cement Usage',
        INT('Daily Cement Usage'[Date]) = INT(yesterday)
    )
)

 

I hope this helps, please give a thumbs up and mark as solved if it does, thanks!

View solution in original post

2 REPLIES 2
rohit1991
Super User
Super User

Hi @kylee_anne 

 

The issue is happening because your reconstructed date is being compared to a datetime column, and the time portion in the datetime is preventing a proper match. To fix this, you need to compare only the date part without the time. You can do this by using INT or DATEVALUE to strip out the time from both sides of the comparison. Also, wrap your filter logic inside a FILTER function so it applies row-by-row to the table. Using ALL inside the FILTER ensures that no existing filters block your comparison. This way, the calculation will correctly match the intended date and return only the relevant rows instead of summing everything.


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!
wardy912
Solution Supplier
Solution Supplier

Hi @kylee_anne 

 

 You need to wrap the second part of the CALCULATE statement in a FILTER function to accurately apply row by row filtering. I've also added INT to ensure the date you are using is only using the date if the type is actually datetime. Finally, i've added +0 to deal with any blanks.

 

Delivered Last 24hrs =
VAR toddy = MAX('Report Date'[Report Date])
VAR yesterday = toddy - 1
RETURN
CALCULATE(
    SUM('Daily Cement Delivered'[Value]) + 0,
    FILTER(
        'Daily Cement Usage',
        INT('Daily Cement Usage'[Date]) = INT(yesterday)
    )
)

 

I hope this helps, please give a thumbs up and mark as solved if it does, thanks!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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