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
dexter2424
Helper I
Helper I

Return latest policy status

Hi All,

 

I need help in PowerBI because cannot figure out how to solve this issue.

I would like to return the latest policy status up to the maximum selected date by policy number.

for example, my slicer is between 1/1/2021 and 1/3/2021. 
I have the following Policy:

Reported Start DatePolicyStatus
01/01/2021123ABCOpen
01/02/2021123ABCOpen
01/03/2021123ABCOpen
01/04/2021123ABCClose

 

I need two cards, one with Open policies and another with Closed policies. Once I set the slicer up to the 1st of March 2021, I would like to see the cards like this:
Open Policy: 1, Closed Policy 0

Once I set the slicer up to the 1st of April 2021, I would like to see the following:
Open Policy: 0, Closed Policy 1

So in summary, I would like to count a policy only once and put it in the open or closed policy bucket. 

I have created a calendar table for the slicer and created some measures, but no luck 😕 If you can give me any advice I would be really thankful.

 

Regards,

Denes

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @dexter2424 

 

You could create two measures by the following formula:

Open =
VAR _last =
    CALCULATE (
        COUNT ( [Policy] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            [Reported Start Date] = MAX ( [Reported Start Date] )
                && [Status] = "Open"))
VAR _count =
    CALCULATE (
        DISTINCTCOUNT ( [Policy] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Status] = "Open" ))
RETURN
    IF ( _last = BLANK (), IF ( _count = 1, 0, -1 ), _last )
Close =
VAR _last =
    CALCULATE (
        COUNT ( [Policy] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            [Reported Start Date] = MAX ( [Reported Start Date] )
                && [Status] = "Close"))
VAR _count =
    CALCULATE (
        DISTINCTCOUNT ( [Policy] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Status] = "Close" )
    )
RETURN
    IF ( _last = BLANK (), IF ( _count = 1, 0, -1 ), _last )

The final output is shown below:

v-yalanwu-msft_3-1621232598340.jpegv-yalanwu-msft_4-1621232613159.pngv-yalanwu-msft_5-1621232617601.png

 

Best Regards,
Community Support Team_ Yalan Wu
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

4 REPLIES 4
v-yalanwu-msft
Community Support
Community Support

Hi, @dexter2424 

 

You could create two measures by the following formula:

Open =
VAR _last =
    CALCULATE (
        COUNT ( [Policy] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            [Reported Start Date] = MAX ( [Reported Start Date] )
                && [Status] = "Open"))
VAR _count =
    CALCULATE (
        DISTINCTCOUNT ( [Policy] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Status] = "Open" ))
RETURN
    IF ( _last = BLANK (), IF ( _count = 1, 0, -1 ), _last )
Close =
VAR _last =
    CALCULATE (
        COUNT ( [Policy] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            [Reported Start Date] = MAX ( [Reported Start Date] )
                && [Status] = "Close"))
VAR _count =
    CALCULATE (
        DISTINCTCOUNT ( [Policy] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Status] = "Close" )
    )
RETURN
    IF ( _last = BLANK (), IF ( _count = 1, 0, -1 ), _last )

The final output is shown below:

v-yalanwu-msft_3-1621232598340.jpegv-yalanwu-msft_4-1621232613159.pngv-yalanwu-msft_5-1621232617601.png

 

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi v-yalanwu-msft, thank you for your solution, there is only 1 exception. 
It shows the exact date matching. I would like to see the latest one. So using the same example above:

Reported Start DatePolicyStatus
01/01/2021123ABC Open
01/02/2021123ABC Close
01/03/2021123ABC Open
01/04/2021123ABC Close
01/05/2021123ABC

 Close

 

Once I select 01/06/2021 it shows a blank result, because there is no result on 01/06/2021. In this case, I would like to see the latest non-blank or latest existing value. so the Closed on 01/05/2021. 
I have tried to modify your query from 

 [Reported Start Date] = MAX ( [Reported Start Date]

to:

 [Reported Start Date] <= MAX ( [Reported Start Date]

 but it's also wrong because the query looks for the latest "Open" and "Closed" policies, so count once as open and count once as closed. 
So the result with this modification is: 1 Open (1/3/2021) and 1 Closed (1/5/2021). 

I would like to see: 0 Open and 1 Closed, because the slider's date is 1/5/2021 and the latest ABC123 Policy was on 1/5/2021, and it's status was Closed, so wanna count as 1 Closed

Thank you very much!!

amitchandak
Super User
Super User

@dexter2424 , with an independent date table for slicer

 

Open  =
var _max = maxx(allselected('Date'), Date[Date])

return
calculate(distinctCOUNT(Table[Policy]), filter(Table, Table[Status]="Open" && Table[Reported Start Date] <=_max)) -
calculate(distinctCOUNT(Table[Policy]), filter(Table, Table[Status]="Close" && Table[Reported Start Date] <=_max))

 

 

close  =

new measure =
var _max = maxx(allselected('Date'), Date[Date])

return
calculate(distinctCOUNT(Table[Policy]), filter(Table, Table[Status]="Close" && Table[Reported Start Date] <=_max))

Thanks Amitchandak,

The solution is mostly right, except for some things. I need to pick up the latest status in the selected period. 
So for example:

Reported Start DatePolicyStatus
01/01/2021123ABC Open
01/02/2021123ABC Close
01/03/2021123ABC Open
01/04/2021123ABC Close
01/05/2021123ABC Close

 

When I select the period between 01/01/2021 and 01/02/2021, it says 1 open and 1 closed it's 0 open and 1 closed. But the period in 01/02/2021 and 01/03/2021, I have 1 open and 1 closed as well, but I need to count it as open because open is the latest one. So I always need to count the latest status. The other thing, if I have only closed ones like in between 01/04/2021 and 01/05/2021, the open count will show -1, because 0 open and 1 closed, it's 0-1=-1

😕
do you have any idea?

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.