Forum Discussion

Päät's avatar
Päät
Frequent Visitor
2 years ago
Solved

Calculate (partial) amount between two dates

Hello, I would like to create a measure to sum up the amount of projects between a specified date range by using a slicer. See an example table below. If the chosen date range is not covered by the ...
  • olgad's avatar
    2 years ago

    Hi, check this out, 

    first you wanna calculate the difference in days you have between start and end date of the project. 

    then you want to see the difference in days between the start date and the min date of the slicer as well as end date of the project and max date of the slicer. In the end, if any of those date differences are negative, meaning the slicer dates are before or after the project, you want to subtract those days. 

    I used 30 as a monthly average of days to calculate the proportions. 

    Datediff = DATEDIFF('Table'[Start],'Table'[End], DAY)
    Partial Amount =
    var DateDiffStart=Calculate(DATEDIFF(min('Date'[Date]),min('Table'[Start]),DAY))
    var DateDiffEnd=Calculate(DATEDIFF(min('Table'[End]),max('Date'[Date]),DAY))
    var StartDate=if(DateDiffStart<0, DateDiffStart, 0)
    var EndDate=if(DateDiffEnd<0, DateDiffEnd, 0)
    var ProjectDaysInSlicerPeriod=DIVIDE(Sum('Table'[Datediff])+StartDate+EndDate, 30)
    var ProjectMonth=Divide(Sum('Table'[Datediff]), 30)
    RETURN
    DIVIDE(ProjectDaysInSlicerPeriod, ProjectMonth)*Sum('Table'[Amount])


    Remark: for Project A, it is not 3/6, but 3/5