Forum Discussion

JGroothedde's avatar
JGroothedde
Icon for Resolver II rankResolver II
1 year ago
Solved

Find count of rows between start-end date in same table

Hi there,   I'm having a brainfart for something that i initially thought would be very easy. I hope someone can help me with this. I have a single table like so: ID person datetime sta...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi JGroothedde ,

    Please refers to the following steps.

    1. Create two dimension tables for the /datetime start/ field and the /datetime planned end/ field

    DimStartime = VALUES('Table'[datetime start])
    
    DimEndtime = VALUES('Table'[datetime planned end])

     

    2. Creates a measure that calculates the count of rows.

    Test = 
    VAR _result = 
    IF(SELECTEDVALUE('DimEndtime'[datetime planned end])>SELECTEDVALUE('DimStartime'[datetime start]),
    CALCULATE(
         COUNTROWS('Table'),
         KEEPFILTERS('Table'[datetime planned end]<=SELECTEDVALUE('DimEndtime'[datetime planned end])&&'Table'[datetime start]>=SELECTEDVALUE(DimStartime[datetime start]))
         ,'Table'[status]="Completed"
         )
        )
        RETURN
    IF(_result<>BLANK(),1,0)


    3. Create slicers using fields from both dimension tables.
    The result is shown below and hopefully meets your needs.


    Please see the attached pbix for reference.

    Best Regards,
    Dengliang Li

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