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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors