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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

Calculate formula issue : Wrong value in bar chart

Hello, 


Sorry if i ask beginner questions. I hope someone can help me. Here is my dax measure formula : 


Vert1 = CALCULATE(
VAR AA = SUMX('Lot 1','Lot 1'[Xp]-'Lot 1'[Prérequis])
VAR BB = IF (AA<0,0,1)
VAR CC = IF(BB>=2,2,BB)
RETURN CC
,Code[Color]="V")

calculate issue.PNG

I don't understand why I have values in my bar chart over 2 whereas i ask to put 2 if my variable goes over 2 . My bar chart is based on 2 other columns value. One column for C1 for competencies and the other C2  C2 is in absciss.


Thanks for your help

1 REPLY 1
OwenAuger
Super User
Super User

Hello @Anonymous 

 

First of all, I also can't explain why this measure would ever return a number other than 0, 1 or 2.

It does look like you intended to write VAR CC slightly differently:

VAR CC = IF(AA>=2,2,BB)

Though that still doesn't explain why you are getting results > 2.

 

I would recommend something like this instead. It puts all the conditions in a single SWITCH function:

Vert1 =
CALCULATE (
    VAR AA =
        SUMX ( 'Lot 1', 'Lot 1'[Xp] - 'Lot 1'[Prérequis] )
    RETURN
        SWITCH ( TRUE (), AA < 0, 0, AA < 1, 1, 2 ),
    Code[Color] = "V"
)

 

Does this give the expected result?

 Regards

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

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.