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

SWITCH statement not calculating correctly

Hi so I have 2 tables with many to many relationship and I have a calculated column which subtracts (correctly) the Customary charge - amount = balance. So I have checked the math and it is correct, now I want to create a new column called Balance =Switch(True(),'Visit'[Balance] = 0, "Fully Paid", 'Visit'[Balance]> 0 && 'Visit'[Balance]< Visit[SumCustomary Charge] , "Partially Paid" , 'Visit'[Balance]= Visit[SumCustomary Charge], "Not Paid", 'Visit'[Balance]<0, "Negative Balance", 'Visit'[Balance] > Visit[SumCustomary Charge], "Amount Greater Than Charge" )

visit table

visit idcustomary charge
100200
200300
205150
300230

 

paymentamount
100200
200203
205150
3000

 

result table should look like this 

visit idcustomary chargeamountbalancetpye
1002002000Fully paid
20030020397Partially Paid
2051501500Fully Paid
3002300230Not Paid
1 ACCEPTED SOLUTION
v-danhe-msft
Employee
Employee

Hi @saanah2019 ,

Could you have create your [Balance] as a measure? Based on my test, you could refer to below measures:

Balance = CALCULATE(SUM(Visit[customary charge]))-CALCULATE(SUM(Table2[amount]))
type = Switch(True(),'Visit'[Balance] = 0, "Fully Paid", 'Visit'[Balance]> 0 && 'Visit'[Balance]< CALCULATE(SUM(Visit[Customary Charge])) , "Partially Paid" , 'Visit'[Balance]= CALCULATE(SUM(Visit[Customary Charge])), "Not Paid", 'Visit'[Balance]<0, "Negative Balance", 'Visit'[Balance] > CALCULATE(SUM(Visit[Customary Charge])), "Amount Greater Than Charge" )

Result:

1.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

Community Support Team _ Daniel He
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-danhe-msft
Employee
Employee

Hi @saanah2019 ,

Could you have create your [Balance] as a measure? Based on my test, you could refer to below measures:

Balance = CALCULATE(SUM(Visit[customary charge]))-CALCULATE(SUM(Table2[amount]))
type = Switch(True(),'Visit'[Balance] = 0, "Fully Paid", 'Visit'[Balance]> 0 && 'Visit'[Balance]< CALCULATE(SUM(Visit[Customary Charge])) , "Partially Paid" , 'Visit'[Balance]= CALCULATE(SUM(Visit[Customary Charge])), "Not Paid", 'Visit'[Balance]<0, "Negative Balance", 'Visit'[Balance] > CALCULATE(SUM(Visit[Customary Charge])), "Amount Greater Than Charge" )

Result:

1.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

Community Support Team _ Daniel He
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.