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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
kav_cris
Frequent Visitor

Measure totals not calculated in a datediff scenario

Hi,

I have a measure called Datediff that calculates the date difference from a list a Purchase dates to the end of each month in the year.
The result looks like this:

kav_cris_0-1681301848389.png

For example on 20th of April I purchased 2 items, each having a 10 days difference to the end of April.

 

What I would like is the total on the April column to show 89 (which is 24+22+11+10+10+9+2+1+0+0).

Then I can calculate the average for the 10 items by dividing the 2 measure Datediff/TotalItems.

The idea is to have the average date difference of all items to the end of each month.

 

My Datediff measure looks like this:

 

Datediff = 

VAR _Days = CALCULATE(
    SWITCH(
    FALSE(),
    SELECTEDVALUE(Item[PurchasedDate]) <= SELECTEDVALUE('Date'[Date]),
    DATEDIFF(SELECTEDVALUE(Item[PurchasedDate]),EOMONTH(MAX('Date'[Date]),0), DAY),
    0
    ), ALL('Date'[Date]), 'Date'[Date]<=MAX('Date'[Date]), Item[Status] = "Stock"
)

VAR _Items = CALCULATE(
    COUNT(Items[ItemID]), Item[Status] = "Stock",
    ALL('Date'[Date]),
    'Date'[Date] <= MAX('Date'[Date]),
    USERELATIONSHIP('Date'[Date],Item[PurchasedDate])
)


RETURN 
   _Days*_Items

 

 

1 ACCEPTED SOLUTION
ppm1
Solution Sage
Solution Sage

Please see this video for how to get your expected totals. 

 

(2) Power BI - Tales from the front #01 - Getting the Right Total - YouTube

 

Pat

Microsoft Employee

View solution in original post

2 REPLIES 2
ppm1
Solution Sage
Solution Sage

Please see this video for how to get your expected totals. 

 

(2) Power BI - Tales from the front #01 - Getting the Right Total - YouTube

 

Pat

Microsoft Employee
kav_cris
Frequent Visitor

Thank you! It helped.

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.