Forum Discussion

ambere's avatar
ambere
Regular Visitor
3 years ago
Solved

Count days between two dates, conditional based on another table

Hi, I’ve been searching for a solution and I find things that are close but still can’t figure out how to make it work for me. I need a simple formula to count school days of enrollment. I have two ...
  • johnt75's avatar
    3 years ago

    Try

    Num school days = SUMX( Student,
        var StartDate = Student[Current Entry Date]
        var EndDate = MIN( TODAY(), Student[Current Exit Date] )
        return CALCULATE(
            COUNTROWS( 'Date' ),
            'Date'[Date] >= StartDate && 'Date'[Date] <= EndDate,
            'Date'[Type] = "School day"
        )
    )
  • v-yueyunzh-msft's avatar
    3 years ago

    Hi , ambere 

    According to your description , you want to calculate school days enrolled by using the start and end date in table 1 (end date should be either end date or today, whichever is sooner.) 

    Here are the steps you can follow:

    (1)My test data is the same you provided.

    (2)We can create a calculated column :

    Days = 
    var _exitdate=IF([Current Exit Date]>TODAY(),TODAY(),[Current Exit Date])
    return
    COUNTROWS(FILTER(Sheet1,'Sheet1'[Date]>=[Current Entry Date]&&'Sheet1'[Date]<=_exitdate&&'Sheet1'[Type]="School Day"))

    (3)Then we can meet your need , the result is as follows:

     

    If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

     

    Best Regards,

    Aniya Zhang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly