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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

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
Anonymous
Not applicable

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

View solution in original post

1 REPLY 1
Anonymous
Not applicable

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

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.