Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

View all the Fabric Data Days sessions on demand. View schedule

Reply
August1987
New Member

Calculating historic counts based on two date columns

Hi,

 

I'm new to Power BI and struggling with something I feel should be relatively easy but I can't seem to get it to work.

 

The table below contains some dummy data as an example and my relationships are;

 

Active

DateTable : FactTable

Date 1 : * ReceivedDate

Inactive

DateTable : FactTable

Date 1 : * ClearedDate

 

IDReceivedDateClearedDateClearedFlag
110/11/2025 N
210/11/2025 N
310/11/2025 N
410/11/202510/11/2025Y
503/11/2025 N
603/11/2025 N
703/11/2025 N
803/11/2025 N
903/11/202510/11/2025Y
1003/11/202503/11/2025Y
1103/11/202503/11/2025Y
1203/11/202503/11/2025Y
1303/11/2025 N
1427/10/202510/11/2025Y
1527/10/202503/11/2025Y
1627/10/202503/11/2025Y
1727/10/202503/11/2025Y
1827/10/2025 N
1927/10/202527/10/2025Y
2027/10/202527/10/2025Y
2127/10/202527/10/2025Y
2220/10/2025 N
2320/10/202510/11/2025N
2420/10/202503/11/2025Y
2520/10/202527/10/2025Y
2620/10/202527/10/2025Y
2720/10/202527/10/2025Y
2820/10/202520/10/2025Y
2920/10/202520/10/2025Y
3020/10/202520/10/2025Y

 

I'm trying to create a measure which will return a count of how many cases were oustanding on a filtered date. I believe this should be a count of the cases received before that date, that are also either currently outstanding (ClearedDate will be blank and ClearedFlag will display 'N') or have a ClearedDate of either on or after that date. Note, dates in the ReceivedDate and ClearedDate column are always a Week Commencing date and I'm using a WC column in the DateTable to filter.

 

Eg. if I filter for 03/11/2025, 17 cases were received before that date, of which 2 are currently outstanding, and 6 have a ClearedDate of either on or after that date so outstanding should be 8.

 

I hope that makes sense but if you need any clarification please let me know. Any help would be very much appreciated 🙂

1 ACCEPTED SOLUTION

Hi @August1987 

 

This seems to be a separate issue to the original question i.e. you now mention a y-axis so there's a chart visual involved.

 

Have you tried my suggestion and checked my example PBIX file?

 

It's very hard to diagnose an issue when you don't supply the full dataset, or your PBIX file, or even some screenshots.  Please supply your PBIX file if you can, it'll make things much easier to help you.

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

7 REPLIES 7
v-saisrao-msft
Community Support
Community Support

Hi @August1987,

Checking in to see if your issue has been resolved. let us know if you still need any assistance.

 

Thank you.

v-saisrao-msft
Community Support
Community Support

Hi @August1987,

Have you had a chance to review the solution we shared by @SolomonovAnton @GeraldGEmerick @PhilipTreacy ? If the issue persists, share the sample Pbix with the expected output so we can help to resolve the issue.

 

Thank you.

PhilipTreacy
Super User
Super User

Hi @August1987 

 

Download example PBIX file with code shown below

 

Your logic was a bit confusing but I think I've figured it out.

 

Based on this: Eg. if I filter for 03/11/2025, 17 cases were received before that date, of which 2 are currently outstanding, and 6 have a ClearedDate of either on or after that date so outstanding should be 8.

 

Then the 17 cases are ID's 14 through 30

 

The 2 outstanding are ID's 18 and 22

 

The other 6 are ID's 14, 15, 16, 17, 23, 24.

 

So filtering on 3 Nov 2025:

 

PhilipTreacy_0-1762905908560.png

 

Note that a table will show 9 records because that's how many match the selected date

 

PhilipTreacy_1-1762905960989.png

 

The measure is to calculate the Outstanding value is:

 

Outstanding = 

VAR _Outstanding_Before = CALCULATE(COUNTROWS(Data), FILTER(ALL(Data), 'Data'[ReceivedDate] < SELECTEDVALUE(Data[ReceivedDate]) && ISBLANK('Data'[ClearedDate]) && 'Data'[ClearedFlag] = "N"))

VAR _Cleared_After = CALCULATE(COUNTROWS(Data), FILTER(ALL(Data), 'Data'[ReceivedDate] < SELECTEDVALUE(Data[ReceivedDate]) && 'Data'[ClearedDate] >= SELECTEDVALUE(Data[ReceivedDate]) ))

RETURN _Outstanding_Before + _Cleared_After

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


GeraldGEmerick
Solution Sage
Solution Sage

@August1987 The sample data doesn't correspond to your specified results but I believe that something along the lines of following should suffice for your purposes:

Open Items = 
VAR _SelectedDate = SELECTEDVALUE( 'Table'[ReceivedDate] )
VAR _Table = FILTER( ALL( 'Table' ), [ReceivedDate] <= _SelectedDate && [ClearedDate] > _SelectedDate )
VAR _Return = COUNTROWS( _Table )
RETURN _Return
SolomonovAnton
Super User
Super User

 

 

Goal: Count cases outstanding on the WC date selected from your DateTable, given:

  • Active rel.: DateTable[Date] → FactTable[ReceivedDate]
  • Inactive rel.: DateTable[Date] → FactTable[ClearedDate]

    Definition (as-of logic): A row is outstanding on date D if:

    1. ReceivedDate < D (received before the WC date), and
    2. ClearedDate is blank or ClearedDate ≥ D.

      1) Core measure (as-of count)

      This measure captures the selected WC date from the date slicer, then ignores the active date relationship when evaluating the fact rows (so you don’t accidentally pre-filter by ReceivedDate). It still respects other report/page slicers (e.g., BU, Region).

      // Outstanding cases as of the selected WC date (received strictly before D)
      Outstanding As Of =
      VAR D =
          MAX ( 'DateTable'[WC] )               // single WC selection or iterates per axis context
      RETURN
      CALCULATE (
          COUNTROWS ( 'FactTable' ),
          FILTER (
              ALLSELECTED ( 'FactTable' ),      // keep non-date slicers
              'FactTable'[ReceivedDate] < D
                  && ( ISBLANK ( 'FactTable'[ClearedDate] )
                       || 'FactTable'[ClearedDate] >= D )
          ),
          REMOVEFILTERS ( 'DateTable' )         // break active ReceivedDate relationship
      );
      Why this pattern?
      • REMOVEFILTERS('DateTable') breaks the active ReceivedDate filter. We use the date slicer only to capture D.
      • ALLSELECTED(FactTable) preserves user slicers on other dimensions while preventing unintended date pre-filtering.
      • Direct date comparisons avoid toggling the inactive ClearedDate relationship.

        2) Optional diagnostics (to reconcile numbers)

        Received before D
        Received Before D :=
        VAR D = MAX ( 'DateTable'[WC] )
        RETURN
        CALCULATE (
            COUNTROWS ( 'FactTable' ),
            FILTER ( ALLSELECTED ( 'FactTable' ), 'FactTable'[ReceivedDate] < D ),
            REMOVEFILTERS ( 'DateTable' )
        )
        Currently outstanding (Cleared is blank)
        Currently Outstanding Before D :=
        VAR D = MAX ( 'DateTable'[WC] )
        RETURN
        CALCULATE (
            COUNTROWS ( 'FactTable' ),
            FILTER ( ALLSELECTED ( 'FactTable' ),
                'FactTable'[ReceivedDate] < D
                && ISBLANK ( 'FactTable'[ClearedDate] )
            ),
            REMOVEFILTERS ( 'DateTable' )
        )
        Cleared on/after D
        Cleared OnOrAfter D (from those received before D) :=
        VAR D = MAX ( 'DateTable'[WC] )
        RETURN
        CALCULATE (
            COUNTROWS ( 'FactTable' ),
            FILTER ( ALLSELECTED ( 'FactTable' ),
                'FactTable'[ReceivedDate] < D
                && NOT ISBLANK ( 'FactTable'[ClearedDate] )
                && 'FactTable'[ClearedDate] >= D
            ),
            REMOVEFILTERS ( 'DateTable' )
        )
        Check: Outstanding = Current + ClearedOn/After
        Outstanding As Of (check) :=
        [Currently Outstanding Before D] + [Cleared OnOrAfter D (from those received before D)]

        3) Your example (03/11/2025)

        • Received Before D (D = 03/11/2025): 17 rows (weeks 20/10 and 27/10).
        • Currently Outstanding Before 😧 2 (IDs 18 & 22 with blank ClearedDate).
        • Cleared OnOrAfter 😧 6 (e.g., IDs 14–17, 23, 24).
        • Outstanding As Of = 2 + 6 = 8

          4) Variations & tips

Thank you for your detailed response, I appreciate it so much.

 

When I've created the measure using my data I'm having a couple of issues. It returns a correct count of outstanding cases (currently 7765); however, when I add another field to the y-axis it shows 7765 for every item within that field. Also, when I add a slicer using the WC date and select a week, it returns a blank result.

 

Any ideas?

Hi @August1987 

 

This seems to be a separate issue to the original question i.e. you now mention a y-axis so there's a chart visual involved.

 

Have you tried my suggestion and checked my example PBIX file?

 

It's very hard to diagnose an issue when you don't supply the full dataset, or your PBIX file, or even some screenshots.  Please supply your PBIX file if you can, it'll make things much easier to help you.

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.