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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.