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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
SethuPower
Frequent Visitor

Count Status as per the Date Filter

Hello All,

 

My input data looks like below. I have a slicer with Date Range. Depending on the Date filter, my output to change 

 

Eg. If the date range is less than or Equal to 25-Jun-18, Then i should get "Open" count as 1 and "Closed" count as Zero.

If date range is less than or equal to 31-Dec-2018, Then i should get "Open" count as 0 and "Closed" count as 1 (final status as per the date range should be considered)

If date range is less than or equal to 30-Mar-2019, Then i should get "Open" count as 1 and "Closed" count as 1

If date range is less than or equal to 15-Dec-2018, Then i should get "Open" count as 2 and "Closed" count as 0

 

Could you please help how my measure should be @Zubair_Muhammad @Ashish_Mathur 

(its getting double counted for me which i want to avoid)

 

IDVersionStatusDateStatus
1120-Jun-18Open
1220-Jun-18Open
1325-Jun-18Open
1427-Jul-18Closed
1531-Dec-18Closed
2115-Dec-18Open
2222-Feb-19Closed
2329-Mar-19Closed

 

1 ACCEPTED SOLUTION

Hi @SethuPower 

In addition to my previous reply,

Create measures

distincount status per day =
CALCULATE (
    DISTINCTCOUNT ( Table1[Status] ),
    FILTER (
        ALLSELECTED ( Table1 ),
        Table1[ID] = MAX ( Table1[ID] )
            && Table1[StatusDate] = MAX ( Table1[StatusDate] )
    )
)

Modify measure

open =
VAR countopen =
    COUNTX (
        FILTER (
            ALLSELECTED ( Table1 ),
            Table1[ID] <> MAX ( Table1[ID] )
                && [open/closed] = "Open"
        ),
        [open/closed]
    )
RETURN
    IF ( [distincount status per day] > 1, countopen - 1, countopen )

Capture16.JPG

Best Regards
Maggie
 
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-juanli-msft
Community Support
Community Support

Hi @SethuPower 

Create measures below

Max date each id = CALCULATE(MAX(Table1[StatusDate]),FILTER(ALLSELECTED(Table1),Table1[ID]=MAX(Table1[ID])))

open/closed = IF(MAX(Table1[StatusDate])=[Max date each id],MAX(Table1[Status]))

open = COUNTX(FILTER(ALLSELECTED(Table1),[open/closed]="Open"),[open/closed])

closed = COUNTX(FILTER(ALLSELECTED(Table1),[open/closed]="Closed"),[open/closed])
Capture6.JPG
Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks Maggie for your efforts. Appreciate a lot

All works fine with your code except one part which is where i am also stuck.

there are cases where on a single date we have two status i.e eg 20-June-18, Version 3 was "Open" and 20-Jun-18, Version 4 has "Closed". Here we need to count only "closed" as 1 and exclude "open" as the latest version has "Closed". however above code includes total of both versions as it fall on the same date.  (it shows Open also as 1 and Closed also as 1"

 

Any idea where we are missing in that situation

 

Hi @SethuPower 

In addition to my previous reply,

Create measures

distincount status per day =
CALCULATE (
    DISTINCTCOUNT ( Table1[Status] ),
    FILTER (
        ALLSELECTED ( Table1 ),
        Table1[ID] = MAX ( Table1[ID] )
            && Table1[StatusDate] = MAX ( Table1[StatusDate] )
    )
)

Modify measure

open =
VAR countopen =
    COUNTX (
        FILTER (
            ALLSELECTED ( Table1 ),
            Table1[ID] <> MAX ( Table1[ID] )
                && [open/closed] = "Open"
        ),
        [open/closed]
    )
RETURN
    IF ( [distincount status per day] > 1, countopen - 1, countopen )

Capture16.JPG

Best Regards
Maggie
 
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-juanli-msft
Community Support
Community Support

Hi @SethuPower 

I still don't understand, based on my understanding, the result should be

date range open(id) close(id) open count close count
<=2018/6/25 1   1 0
<=2018/12/12 1 1 1 1
<=2018/12/31   1 0 1
<=2019/3/30   1,2 0 2

 

Best Regards
Maggie

 

 

Hi Maggie, 

Correction only on 12-12-2018 and others look correct

date rangeopen(id)close(id)open countclose count
<=2018/6/251 10
<=2018/12/12 1 1
<=2018/12/31 101
<=2019/3/30 1,202

 

I tried below code and it works for me only when i put this measure in a visual table and add ID column (both to values) it shows correct value. Now i want to show the total / count of what is displayed in table in a CARD. Not sure how to get the total / count of this measure 

RunningVersion = 

Var Temp = CALCULATE(
                    MAX( Table1[Version]) ,
                    FILTER( Table1,
                    MAXX( FILTER( Table1, EARLIER( Table1[ID] ) = Table1[ID] ),1)
                        )
                    )

Var X = CALCULATE( FIRSTNONBLANK(Table1[Status],1),
                        FILTER(Table1, Table1[ID] = Table1[ID]),
                        FILTER(Table1, Table1[Version] = Temp )
                        )
     
Return X

 

 

v-juanli-msft
Community Support
Community Support

Hi @SethuPower 

Is my understanding correct?

It is to say, for date 2018/1/26, "Open" count  as 2, and "Closed" count as 0.

Capture3.JPG

 

 
Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Maggie,

 

Thanks for your reply. On 26-Jan-2018, Open and Close count both should be 0 as the first starting date (or minimum date) is 20-Jun-2018. I tried below to get the max version no for that date range and pull the status for that.. however it is picking the maximum of version no irrespective of slicer date and pulling the last status. (2 measures - one for Open Count and one for Closed Count)

 

 
LastOpenCount = 

 VAR Temp =

    ADDCOLUMNS(

            SUMMARIZE(Table1,

            Table1[ID],

            "LastVersion",MAX(Table1[Version])

            ), "CloseOpenC",

                Calculate(FIRSTNONBLANK(Table1[Status],1),

                        FILTER(Table1, Table1[ID]= Table1[ID]),

                        FILTER(Table1, VALUE(Table1[Version])=VALUE([LastVersion]))

                        )

      )

Return

Calculate(

DISTINCTCOUNT( [ID] ),

Filter(Temp, [CloseOpenC]="Open")

)

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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