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! Request now

Reply
newpbiuser01
Helper V
Helper V

Formatting difference between two numbers

Hello,

 

I'm trying to use a measure to calculate the difference between last years and this year spend and format it to show the data as thousands, millions etc. 

 

I'm using the following measure:

Payment YoY = 

VAR PaymentCurrentY = CALCULATE(SUM('Table1[Amount], FILTER('Table1',[Y] = "2023"))
VAR PaymentPreviousY = CALCULATE(SUM('Table1[Amount], FILTER('Table1',[Y] = "2022"))
VAR YoYAmount =PaymentCurrentY - PaymentPreviousY
RETURN
     SWITCH(TRUE (),
        YoYAmount< 1000 && NOT(ISBLANK(YoYAmount)), FORMAT(YoYAmount,"$0.0"),
        YoYAmount >= 1000 && YoYAmount < 1000000 , CONCATENATE ( FORMAT(YoYAmount / 1000,"$0.0"), "k" ),
        YoYAmount >= 1000000 && YoYAmount < 1000000000 ,  CONCATENATE ( FORMAT(YoYAmount / 1000000,"$0.0"),"M"  ),
        YoYAmount >= 1000000000 && YoYAmount <= 1000000000000 ,  CONCATENATE (FORMAT(YoYAmount/1000000000,"$0.0"), "B" ) )
 
However, this doesn't seem to work. When I applied the same switch statement for formatting on just this years spend (without subtracting the previous from the current) the formatting works like a charm:
 

Payment 2023= 

VAR PaymentCurrentY = CALCULATE(SUM('Table1[Amount], FILTER('Table1',[Y] = "2023"))
VAR PaymentPreviousY = CALCULATE(SUM('Table1[Amount], FILTER('Table1',[Y] = "2022"))
VAR YoYAmount =PaymentCurrentY
RETURN
     SWITCH(TRUE (),
        YoYAmount< 1000 && NOT(ISBLANK(YoYAmount)), FORMAT(YoYAmount,"$0.0"),
        YoYAmount >= 1000 && YoYAmount < 1000000 , CONCATENATE ( FORMAT(YoYAmount / 1000,"$0.0"), "k" ),
        YoYAmount >= 1000000 && YoYAmount < 1000000000 ,  CONCATENATE ( FORMAT(YoYAmount / 1000000,"$0.0"),"M"  ),
        YoYAmount >= 1000000000 && YoYAmount <= 1000000000000 ,  CONCATENATE (FORMAT(YoYAmount/1000000000,"$0.0"), "B" ) )
 
newpbiuser01_0-1683148073026.png

 Why does the formatting not work when I try to apply it on the current spend - previous spend? I checked and the YoYAmount is a number, so it should be the same. 

 

Thank you for your help!

1 ACCEPTED SOLUTION
Wilson_
Super User
Super User

Hello,

 

All your YoY values are negative, and therefore are all less than 1,000. The implicit assumption in your SWITCH statement is that YoYAmount will always be positive. Therefore, you need to wrap all your YoYAmount variables in the SWITCH statement in an ABS function.


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

2 REPLIES 2
Wilson_
Super User
Super User

Hello,

 

All your YoY values are negative, and therefore are all less than 1,000. The implicit assumption in your SWITCH statement is that YoYAmount will always be positive. Therefore, you need to wrap all your YoYAmount variables in the SWITCH statement in an ABS function.


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.

Top Solution Authors
Top Kudoed Authors