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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
ramiaburayeh
Regular Visitor

DAX Count based on Criteria outside the range of filter

Dear all,

I want to count distinict  all cases for each day gourp by the last action per day( Open, Under Review, Close) and add the cases that has not been closed ( Action <> Close) from prevous date. The following is the dataset: 

Case_IDActionCreated_Date      
AOpen

20/6/2022 12:00:00 

 
AUnder Review20/6/2022 12:15:00 
BOpen21/6/2022 10:00:00 
BUnder Review22/6/2022 11:07:00 
AClose22/6/2022 12:00:00 
COpen22/6/2022 11:07:00 
CUnder Review23/6/2022 11:07:00 
DOpen23/6/2022 16:07:01 
DUnder Review23/6/2022 16:07:01 

 

The following table illustrates the expected results (Total) column

 

DateActionTotal Cases Open from past datesTotal
20/6/2022 Under Review101
21/6/2022Open101
21/6/2022Under Review011
22/6/2022Under Review101
22/6/2022Close101
22/6/2022Open112
23/6/2022Under Review213
23/6/2022Open011

 

Thank you in advance

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Untitled.png

 

Total Cases: = 
VAR _currentdate =
    MAX ( 'Calendar'[Date] )
VAR _currentactionindex =
    MAX ( 'Action'[Index] )
VAR _newtable =
    SUMMARIZE (
        FILTER ( ALL ( Data ), Data[Created_Date] = _currentdate ),
        'Case'[Case_ID],
        'Action'[Index]
    )
VAR _addmaxactionindex =
    SUMMARIZE (
        ADDCOLUMNS (
            _newtable,
            "@maxactionindex",
                MAXX (
                    FILTER ( _newtable, 'Case'[Case_ID] = EARLIER ( 'Case'[Case_ID] ) ),
                    'Action'[Index]
                )
        ),
        'Case'[Case_ID],
        [@maxactionindex]
    )
RETURN
    COUNTROWS (
        FILTER ( _addmaxactionindex, [@maxactionindex] = _currentactionindex )
    )

 

Open from past: = 
VAR _currentdate =
    MAX ( 'Calendar'[Date] )
VAR _currentactionindex =
    MAX ( 'Action'[Index] )
VAR _todayclosecase =
    SUMMARIZE (
        FILTER (
            ALL ( Data ),
            Data[Created_Date] = _currentdate
                && Data[Action] = "Close"
        ),
        'Case'[Case_ID]
    )
VAR beforecurrenttable =
    SUMMARIZE (
        FILTER (
            ALL ( Data ),
            Data[Created_Date] < _currentdate
                && Data[Case_ID] <> _todayclosecase
        ),
        'Case'[Case_ID],
        'Action'[Index]
    )
VAR _addmaxactionindex =
    FILTER (
        SUMMARIZE (
            ADDCOLUMNS (
                beforecurrenttable,
                "@maxactionindex",
                    MAXX (
                        FILTER ( beforecurrenttable, 'Case'[Case_ID] = EARLIER ( 'Case'[Case_ID] ) ),
                        'Action'[Index]
                    )
            ),
            'Case'[Case_ID],
            [@maxactionindex]
        ),
        [@maxactionindex] <> 3
    )
RETURN
    COUNTROWS (
        FILTER ( _addmaxactionindex, [@maxactionindex] = _currentactionindex )
    )

 

Total measure: = 
[Total Cases:] + [Open from past:]

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
ramiaburayeh
Regular Visitor

Thank you very much

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Untitled.png

 

Total Cases: = 
VAR _currentdate =
    MAX ( 'Calendar'[Date] )
VAR _currentactionindex =
    MAX ( 'Action'[Index] )
VAR _newtable =
    SUMMARIZE (
        FILTER ( ALL ( Data ), Data[Created_Date] = _currentdate ),
        'Case'[Case_ID],
        'Action'[Index]
    )
VAR _addmaxactionindex =
    SUMMARIZE (
        ADDCOLUMNS (
            _newtable,
            "@maxactionindex",
                MAXX (
                    FILTER ( _newtable, 'Case'[Case_ID] = EARLIER ( 'Case'[Case_ID] ) ),
                    'Action'[Index]
                )
        ),
        'Case'[Case_ID],
        [@maxactionindex]
    )
RETURN
    COUNTROWS (
        FILTER ( _addmaxactionindex, [@maxactionindex] = _currentactionindex )
    )

 

Open from past: = 
VAR _currentdate =
    MAX ( 'Calendar'[Date] )
VAR _currentactionindex =
    MAX ( 'Action'[Index] )
VAR _todayclosecase =
    SUMMARIZE (
        FILTER (
            ALL ( Data ),
            Data[Created_Date] = _currentdate
                && Data[Action] = "Close"
        ),
        'Case'[Case_ID]
    )
VAR beforecurrenttable =
    SUMMARIZE (
        FILTER (
            ALL ( Data ),
            Data[Created_Date] < _currentdate
                && Data[Case_ID] <> _todayclosecase
        ),
        'Case'[Case_ID],
        'Action'[Index]
    )
VAR _addmaxactionindex =
    FILTER (
        SUMMARIZE (
            ADDCOLUMNS (
                beforecurrenttable,
                "@maxactionindex",
                    MAXX (
                        FILTER ( beforecurrenttable, 'Case'[Case_ID] = EARLIER ( 'Case'[Case_ID] ) ),
                        'Action'[Index]
                    )
            ),
            'Case'[Case_ID],
            [@maxactionindex]
        ),
        [@maxactionindex] <> 3
    )
RETURN
    COUNTROWS (
        FILTER ( _addmaxactionindex, [@maxactionindex] = _currentactionindex )
    )

 

Total measure: = 
[Total Cases:] + [Open from past:]

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.