Forum Discussion

wstegemann's avatar
wstegemann
Frequent Visitor
2 years ago

Historical Count with Conditions

Hello,

 

I am trying to use a history file with effective dates to pull values based on any date. For example: I want a count of any records with the job code "X" in Dec-2023. With a history file I would need to look back at the job code on most recent date before the date I am looking at. I created this measure to pull this:

Job Code at Date =
LASTNONBLANKVALUE (
    FILTER (
        ALL ( 'Job History'[Effective Date] ),
        'Job History'[Effective Date] <= MIN ( 'Calendar'[Date] )
    ),
    MIN ( 'Job History'[Job Code] )
)

For this sample data in Dec-2023 (12/1/2023) the count should be 20

 

I have created a conditional column and an accompaniying "at date" measure called Agent Indicator/Agent at Date to make the filtering and summation easier.

 

When I try to put the Agent at Date measure in a visual for a single employee, it displays a 1 or a 0 depending on the date which is the expected behavior. I would expect that adding in more employees would show the sum of the Agent Indicator/Agent at Date on any date. For example if there are 10 active employees on 1/1/2023 and 3 of them match the job code criteria, the visual should display a 3 for that date. This is not what happens. It seems to filter the visual to include only certain employees on certain days. I am sure there is some kind of code or relationship issue, but I don't know how to troubleshoot.

 

I have 3 tables:

Calendar: A standard date table

Roster: A report containing employee information as of the current date, one row per employee

Job History: A report containing all updates to all employee records, multiple rows per employee (It is possible to have more than one row per employee per date, but each change is unique)

 

 

I am pretty sure that the Job history and Calendar tables should be related, but creating a relationship forces all visuals containing data from the Job History table to only display for dates that are present in the Job History table. I would like to include all dates in between so I have made the relationship inactive.

 

I have linked my sample pbix file here:

Sample.pbix 

 

Any help would be greatly appreciated

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi wstegemann ,

    I don't have access to your pbix file and can only provide approximate dax formulas based on your description. Please refer to it if it helps you.

     

    Job Code Count at Date = 
    CALCULATE (
        COUNTROWS ( 'Job History' ),
        FILTER (
            ALL ( 'Job History' ),
            'Job History'[Effective Date] <= MAX ( 'Calendar'[Date] )
            && 'Job History'[Job Code] = "X"
        )
    )

     

     

    How to Get Your Question Answered Quickly - Microsoft Fabric Community

     

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

     

    Best Regards
    Community Support Team _ Rongtie

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

     

     

     

     

    • wstegemann's avatar
      wstegemann
      Frequent Visitor

      Hi Anonymous,

      My explanation of the issue is a bit lacking without having the pbix to reference. Is there any good way for me to provide this for you to take a look at?