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
ttdtbv
Regular Visitor

Count Return Policy in life insurance

Dear all,

I have a problem, please help me.

I want to count Return Policy?

in which "Return Policy is:

               1/ Policy have StartDate within the EndDate +- 3 month {datediff(EndDate, StartDate, month)<=3}

               2/ Repeat Buyer or Repeat Receiver or Buyer become Receiver or Receiver become Buyer"

Many thanks 

Data: 

https://docs.google.com/spreadsheets/d/15H3JKehCXx9feFgR-c-0w31t5NsZx4ko/edit?usp=sharing&ouid=10231...

 

PolicyIdStartDateEndDateBuyerReceiver 
101/01/200001/01/2022B1R1 
201/02/202201/02/2030B1R2Return Policy, B1 repeat, datediff(EndDate, StartDate, month)<=3
301/05/202201/05/2030B1R3Not Return Policy, datediff(EndDate, StartDate, month) > 3 
401/03/202201/03/2030R1R4Return Policy, R1 repeat from Receiver to Buyer, datediff(EndDate, StartDate, month)<=3
501/02/202201/02/2030B2R5Not Return Policy, not repeat Buyer or Receiver
1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @ttdtbv ,

I created a sample pbix file(see the attachment), please check if that is what you want. You can create two measures as below to get it:

Flag = 
VAR _selbuyer =
    SELECTEDVALUE ( 'Table'[Buyer] )
VAR _selreceiver =
    SELECTEDVALUE ( 'Table'[Receiver] )
VAR _selsdate =
    SELECTEDVALUE ( 'Table'[StartDate] )
VAR _seledate =
    SELECTEDVALUE ( 'Table'[EndDate] )
VAR _preedate =
    CALCULATE (
        MAX ( 'Table'[EndDate] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            ( 'Table'[Buyer] = _selbuyer
                || 'Table'[Receiver] = _selbuyer )
                && 'Table'[EndDate] < _seledate
        )
    )
VAR _datediff =
    DATEDIFF ( _selsdate, _preedate, MONTH )
RETURN
    IF ( ISBLANK ( _datediff ), BLANK (), IF ( _datediff <= 3, 1, BLANK () ) )
Count of return policy = COUNTX ( FILTER ( ALLSELECTED ( 'Table'[PolicyId] ), [Flag] = 1 ), [PolicyId] )

yingyinr_0-1669974906087.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
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

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

Hi @ttdtbv ,

I created a sample pbix file(see the attachment), please check if that is what you want. You can create two measures as below to get it:

Flag = 
VAR _selbuyer =
    SELECTEDVALUE ( 'Table'[Buyer] )
VAR _selreceiver =
    SELECTEDVALUE ( 'Table'[Receiver] )
VAR _selsdate =
    SELECTEDVALUE ( 'Table'[StartDate] )
VAR _seledate =
    SELECTEDVALUE ( 'Table'[EndDate] )
VAR _preedate =
    CALCULATE (
        MAX ( 'Table'[EndDate] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            ( 'Table'[Buyer] = _selbuyer
                || 'Table'[Receiver] = _selbuyer )
                && 'Table'[EndDate] < _seledate
        )
    )
VAR _datediff =
    DATEDIFF ( _selsdate, _preedate, MONTH )
RETURN
    IF ( ISBLANK ( _datediff ), BLANK (), IF ( _datediff <= 3, 1, BLANK () ) )
Count of return policy = COUNTX ( FILTER ( ALLSELECTED ( 'Table'[PolicyId] ), [Flag] = 1 ), [PolicyId] )

yingyinr_0-1669974906087.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

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

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.

Top Solution Authors