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
saanah2019
Helper II
Helper II

help creating conditional statement using 2 tables

Hi, I have 2 tables Visit and Payment.

Visit
visit it
program
first bill insurance
customary charge
contractual charge
date first bill
date of service

Visit IdFirst Bill Insurancecustomary Chargecontractualprogramfirst billdate of service 
100Aetna10060acp1/1/20181/1/2018
100Aetna10060acp1/1/20181/1/2018
200Fidelis200160fed1/1/20181/1/2018
300Healthfirst300260fed1/1/20181/1/2018
300Healthfirst300260fed1/1/20181/1/2018


Payment
visit id
amount
activity type
insurance name
date - transaction

Visit Id Payment Insurance amountactivity typedate transaction
100 aetna 0payment10/1/2018
100 fidelis 80payment10/5/2018
200 fidelis 150write-off10/1/2018
300 healthfirst 0payment10/1/2018
300 aetna 200write-off10/6/2018

 

I will filter on visit.date of service for calendar year of 2018
I want to create a column called Visit Balance which will subtract visit.customary charge - payment.amount
I want to create a column called "Type" which will:

- check each visit id and if there are more than one visit ids, then check the intial bill insurance and the insurance name from payment and if they are same then return 0, 

-  check the intial bill insurance and the insurance name from payment and if they are different then return 1, and then for all the 1s.

then for all the visit ids with 1 that we just created, the visit id with min date of transaction will return not collectable and for the the max date of transaction will return "collectable" and if there is only one visit id, then return"collectable"

 

This should be the end result

Visit IdFirst Bill InsurancePayment Insurancecustomary Chargecontractual amountBalance Leftfirst billdate transactionstatus
100Aetnaaetna1006001001/1/201810/1/2018uncollectable
100Aetnafidelis1006080201/1/201810/5/2018collectable
200Fidelisfidelis200160150501/1/201810/1/2018colletable
300Healthfirsthealthfirst30026003001/1/201810/1/2018uncollectable
300Healthfirstaetna3002602001001/1/201810/6/2018collectable
          
1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @saanah2019 ,

 

1. To create  M-M relationship between tables as below.

 

Capture.PNG

 

2.Create measures as below to the the excepted result.

 

Balance Left = CALCULATE(MAX(Visit[customary Charge]))- CALCULATE(MAX(Payment[ amount]))
status = 
VAR countro =
    COUNTROWS ( Visit )
VAR mindate =
    CALCULATE (
        MIN ( 'Payment'[date transaction] ),
        ALLEXCEPT ( Payment, Payment[Visit Id] )
    )
RETURN
    IF (
        ISBLANK ( [Balance Left] ),
        BLANK (),
        IF (
            countro = 1,
            "colletable",
            IF (
                MAX ( Payment[date transaction] ) = mindate,
                "uncollectable",
                "collectable"
            )
        )
    )

2.PNG

 

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

View solution in original post

2 REPLIES 2
v-frfei-msft
Community Support
Community Support

Hi @saanah2019 ,

 

1. To create  M-M relationship between tables as below.

 

Capture.PNG

 

2.Create measures as below to the the excepted result.

 

Balance Left = CALCULATE(MAX(Visit[customary Charge]))- CALCULATE(MAX(Payment[ amount]))
status = 
VAR countro =
    COUNTROWS ( Visit )
VAR mindate =
    CALCULATE (
        MIN ( 'Payment'[date transaction] ),
        ALLEXCEPT ( Payment, Payment[Visit Id] )
    )
RETURN
    IF (
        ISBLANK ( [Balance Left] ),
        BLANK (),
        IF (
            countro = 1,
            "colletable",
            IF (
                MAX ( Payment[date transaction] ) = mindate,
                "uncollectable",
                "collectable"
            )
        )
    )

2.PNG

 

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

@v-frfei-msft hey, thanks for your help but the balance left is not coming out correct for me and as a result the status are all wrong. 

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.