cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
saanah2019 Regular Visitor
Regular Visitor

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

Accepted Solutions
Community Support Team
Community Support Team

Re: help creating conditional statement using 2 tables

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

Re: help creating conditional statement using 2 tables

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

saanah2019 Regular Visitor
Regular Visitor

Re: help creating conditional statement using 2 tables

@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
New Kudos Received Badges Coming

New Kudos Received Badges Coming

Kudos to you if you earned one of these! Check your inbox for a notification.

Microsoft Implementation for Communities Wins Award

Microsoft Implementation for Communities Wins Award

Learn about the award-winning innovation that was implemented across Microsoft’s Business Applications Communities.

Power Platform World Tour

Power Platform World Tour

Find out where you can attend!

Top Kudoed Authors (Last 30 Days)
Users online (5,047)