Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

Dynamic count based on open and start date with date filter slicer

Dear community, 

I am looking for a solution to count or show a specific status depending on a start and end date. 

Use case: data from a recruiting tool. Jobs are "open" as soon as there is a start date and "Filled" as soon as there is a "Date Closed". 

I would like to achieve to find the count of jobs that were "open" at a certain date or date range when filtering by date dynamically and finally having also charts to show the evolution over time. 

 

I have placed this issue several times and seen several similar posts but I could neither replicate the already existing solutions nor the ones that had been kindly provided to me. I am not sure if there is an issue in my date table (counting in fiscal years starting in July), the relationships or the formulas themselves. 

 

Thank you very much in advance!!

 

Summary:

 

Solution 1 proposed =
VAR _N1 =CALCULATE (COUNT ( Jobs[Job Req ID] ),
FILTER (ALL ( Jobs),
Jobs[Date Created]>= SELECTEDVALUE ( 'Fiscal Year Table'[Date] )
&& [Closed Date] = BLANK ()
&& [Status] = "Open"
)
)
VAR _N2 =CALCULATE (COUNT ( Jobs[Job Req ID] ),
FILTER (ALL ( Jobs ),
[Date Created] <= SELECTEDVALUE ( 'Fiscal Year Table'[Date] )
&& [Closed Date] >= SELECTEDVALUE ( 'Fiscal Year Table'[Date] )
&& [Status] = "Filled"
)
)
RETURN
_N1 + _N2
 

 

Solution 2 proposed =
VAR _MAXDATE =
MAX ( 'Fiscal Year Table'[Date] )
RETURN
IF (
MAX ( Jobs[Date Created] ) <= _MAXDATE,
IF (
MAX ( Jobs[Closed Date] ) = BLANK ()
|| MAX ( Jobs[Closed Date] ) >= _MAXDATE,
"Open",
"Filled"
),
"Filled"
)
 

 

Date Table:

Fiscal Year Table = CALENDARAUTO(6)
Fiscal Month N° = (MONTH(EDATE('Fiscal Year Table'[Date], -6)))
Fiscal Quarter = "Q" & (QUARTER(EDATE('Fiscal Year Table'[Date], -6)))
Fiscal Year =
VAR CurrYear = RIGHT(YEAR('Fiscal Year Table'[Date]),2)
VAR LastYear = RIGHT(YEAR('Fiscal Year Table'[Date])-1,2)
VAR NewYear = RIGHT(YEAR('Fiscal Year Table'[Date])+1,2)
VAR FiscalYear =
SWITCH(
TRUE(),
MONTH('Fiscal Year Table'[Date]) >= 4,
CurrYear & "-" & NewYear,
LastYear & "-" & CurrYear
)
RETURN
FiscalYear

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

7 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    If anyone can tell me how to upload the pbix, I can send the file, but it tells me it is not supported...

  • Anonymous's avatar
    Anonymous
    Not applicable
    Job Req IDStatusDate CreatedClosed Date
    1Filled1.16.20183.8.2018
    2Filled1.16.20184.17.2018
    3Filled1.16.20186.20.2018
    4Filled1.23.20183.6.2018
    5Filled1.25.20183.19.2018
    6Filled2.12.20186.25.2018
    7Filled2.12.20186.13.2018
    8Filled2.13.20187.5.2018
    9Filled2.14.20185.8.2018
    10Filled2.19.20186.25.2018
    11Filled2.19.20186.27.2018
    12Filled2.19.20185.29.2018
    13Filled2.19.20184.2.2018
    14Filled2.19.20184.17.2018
    15Filled2.19.20184.13.2018
    16Filled2.19.20186.7.2018
    17Filled2.19.20188.1.2018
    18Filled2.20.20184.2.2018
    19Filled2.22.20187.16.2018
    20Filled2.22.20184.13.2018
    21Filled3.14.20187.20.2018
    22Filled4.5.20185.16.2018
    23Filled4.5.20187.2.2018
    24Filled4.12.20186.25.2018
    25Filled4.19.20186.6.2018
    26Filled4.27.20185.11.2018
    27Filled5.3.20186.11.2018
    28Filled5.16.20187.5.2018
    29Filled5.16.20186.6.2018
    30Filled6.14.20187.23.2018
    31Filled6.28.20187.10.2018
    32Filled6.29.20188.21.2018
    33Filled7.2.20189.11.2018
    34Open7.12.2019 
    35Filled7.15.201912.19.2019
    36Open7.15.201912.2.2019
    37Filled7.15.20199.24.2019
    38Filled7.15.20199.24.2019
    39Filled7.15.20192.4.2020
    40Filled7.15.201910.2.2019
    41Filled7.16.20193.2.2020
    42Filled7.16.20198.6.2019
    43Filled7.16.20198.20.2021
    44Filled7.16.20199.24.2019
    45Filled7.16.20198.15.2019
    46Filled7.16.20199.24.2020
    47Filled7.16.20193.9.2020
    48Filled7.16.20194.29.2020
    49Filled7.16.20192.28.2020
    50Filled7.16.20197.18.2019
    51Filled7.17.20198.23.2021
    52Filled7.18.201911.12.2019
    53Filled7.18.201910.7.2019
    54Filled7.18.201912.9.2019
    55Filled7.18.201912.3.2020
    56Filled7.18.201910.31.2019
    57Open7.18.201911.6.2019
    58Open7.18.201912.16.2019
    59Filled7.19.201910.1.2019
    60Filled7.23.201910.1.2019
    61Filled7.26.20198.19.2021
    62Filled7.26.20194.30.2020
    63Filled7.26.20194.1.2020
    64Filled8.5.20193.9.2020
    65Filled8.5.20197.14.2021
    66Filled8.5.20192.22.2021
    67Filled8.7.201910.31.2019
    68Filled8.7.20194.28.2020
    69Filled8.8.20199.24.2019
    70Filled8.8.20192.24.2020
    71Filled8.8.20192.24.2020
    72Filled8.8.20193.4.2020
    73Filled8.12.20194.28.2020
    74Filled8.16.201910.31.2019
    75Filled8.16.20191.30.2020
    76Filled8.21.201910.31.2019
    77Filled8.26.201911.26.2019
    78Filled8.27.20199.16.2021
    79Filled8.27.20199.16.2021
    80Filled8.27.20199.16.2021
    81Filled8.27.20199.16.2021
    82Filled8.27.20199.16.2021
    83Filled8.27.20199.16.2021
    84Filled8.27.20199.16.2021
    85Filled8.27.20199.16.2021
    86Filled8.27.20199.16.2021
    87Filled8.30.201911.20.2019
    88Filled9.2.201911.4.2019
    89Filled9.4.20192.18.2020
    90Filled9.4.20198.6.2020
    91Filled9.10.20192.17.2020
    92Filled9.17.201910.17.2019
    93Filled9.18.20193.10.2020
    94Filled9.20.20194.8.2020
    95Filled9.20.20193.17.2020
    96Filled9.23.20193.10.2020
    97Filled9.25.20191.30.2020
    98Filled9.26.201911.20.2019
    99Filled9.27.20193.10.2020
  • v-jingzhang's avatar
    v-jingzhang
    Community Support

    Hi Anonymous 

     

    Things will be different when you filter on a specific Date or a date range. When filtering only a specific date, the current solution 1 and solution 2 should work well as one date could only be a created date, or a closed date, or a date between those two dates. The status is easy to judge. 

     

    However, when you filter to a date range, let's take a month as an example, there are four situations for the status of a job Req. I draw a picture as below. If we select Jan 2020, the status of situation 4 is clear to be "Open" based on your description. 

     

    For situation 1, it was created and closed in the same month and the range between two dates are less than the month range, so do you want to count it as "Open" or "Filled" in Jan 2020?

     

    For situation 2 and 3, their Req open ranges cross two months and neither calendar month is fully covered. So how do you want to count their status in two months? 

     

    These situations also happen when you expand the filtered range to a quarter or a year. Apparently the situation 2 in my example cross two different quarters and different years. You need to determine how you want to count the status for job Reqs that have the situation 1, 2, 3. Give us a specific result "Open" or "Filled" for each month. Then we can help provide a solution that can meet your need. We cannot make the decisions for you on whether it should be "Open" or "Filled". 

     

    Best Regards,
    Community Support Team _ Jing

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Jing,

       

      Thank you very much for your answer. 

      The scenarios you drew are exactly the behaviour I am trying to calculate. 

      It doe not have to show "Open" or "Filled" I thought it could be an option to calculate it easier if it was shown. 

      The rational would be to count the number of reqs that were open, but does not need to show "open". As per your example above it should count:

       

      Is this feasible? 

      To answer the question regarding 2 and 3: As long as in a month it was open it should count as such even if it was filled inbetween. 

       

      Let me know if it is clear enough.

      Unfortunately I could not upload the pbix, it tells me "the file type pbix is not supported". If there is a way to upload it I can send you the sample.  

       

       

       

       

       

  • mlearning's avatar
    mlearning
    Frequent Visitor

    This is a little old, but I have a possible solution. I was struggling to build a rolling count of expiring points (HR management call-out points). The points would expire after a set time window.

     

    I had a date. and a point value. I duplicated the date into "expire date" and added my expiration value to it (i.e. expire date = date + N_days). I had a point value so I duplicated that entire column and multiplied iy by -1 (this makes it a negative counterpart to whatever is in "points"). I did this in excel before importing.

     

    So it would look like this:

    Name | Points | NegPoints | Date | ExpireDate

    John Doe | 1 | -1 | 5/2/2024 | 7/31/2024

    Jane Doe | 1 | -1| 5/11/2024 | 8/9/2024

     

    After importing I unpivoted the two date fields. It lumped them under "Attribute" which I renamed to "DateType"

     

    Name | Points | NegPoints | DateType | PtsDate

    John Doe | 1 | -1 | Date | 5/2/2024

    John Doe | 1 | -1 | ExpireDate | 7/31/2024

    Jane Doe | 1 | -1 | Date | 5/11/2024

    Jane Doe | 1 | -1 | ExpireDate | 8/9/2024

     

    How to make the rolling window? I ran into many problems and found precious little help online for it. I created a new column as a measure called PointsCheck. Here's what I did:

     

    PointsCheck = IF(
        PointsReported[DateType] = "Date",
        PointsReported[Points],
        PointsReported[NegPoints]
        )
    Basically if the date is within whatever I'm displaying, return the positive points. If it isn't, give the negative points.
     
    Then when you get to the actual code, you just sum up PointsCheck instead of the points themselves. How does it work? Instead of getting crazy and having multiple conflicting filters or formulas that break constantly, it's just a simple sum and the +/- takes care of the rest for you. I'm only cointing when there's a discrete change in the value of points. So if there's a 4 day gap between changes then it jumps up again or drops. You can tweak that however you like to reflect daily/weekly chart intervals.

     

    CALCULATE(
        SUM(PointsReported[PointsCheck]),  //  PointsCheck is noted above, the -/+ chooser
            FILTER(ALLSELECTED(PointsReported), // This is part of a "choose a name to see the stats" slicer. YMMV.
                PointsReported[PtsDate] <= MAX(PointsReported[PtsDate]) // add the -/+ points where the date is between
                                                                                                                // the start/expire dates
                )
        )
     
     
     
     
    I came at it from another direction. Maybe not very elegant, but it works. I didn't find a visual that showed what I wanted, so I made-do with a stepped line with a fill color. Otherwise, the logic is: With some redundancy, set a plus count and a minus count for every record you need counted. Then do some logic to pre-define if you're counting or subtracting based on the the date. THEN just count the pre-defined value instead of trying to do it all at once. 
    • mlearning's avatar
      mlearning
      Frequent Visitor

      For my needs I wanted a nondestructive points modifier. You could just as easily add the code into the points column and make it positive or negative based on the date type and have 1 less column, and an easier sum code. Just a thought. This isn't perfect, and I can see ways to change it in future projects. Good luck!