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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
fisqkuz1
Frequent Visitor

measure with multiple if statements

hi all 

 

coming from a python background, i am trying to get the hang of dax.

however I am having trouble with the following attempt:

 

Revenue or Cost =
IF(table[col] = "short" & table[col2] > 0, 2, 1
ELIF(table[col] = "long" & table[col2] > 0, 1, 2
ELSE, 1, 2)
 
i can't figure out how to get this in a simple measure rather than a new column
1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi, @fisqkuz1 

Try measure formula like the following:

 

Measure = 
var _col=MAX('Table'[col])
var _col2=MAX('Table'[col2])
return 
SWITCH(TRUE(),
    _col="short"&&_col2>0,2,
    _col="short"&&_col2<>0,1,
    _col="long"&&_col2>0,1,
    _col="long"&&_col2<>0,2,
    2
)

 

If it doesn't work, pelase share your sample data and expected result in excel.

Best Regards,
Community Support Team _ Eason

View solution in original post

4 REPLIES 4
v-easonf-msft
Community Support
Community Support

Hi, @fisqkuz1 

Try measure formula like the following:

 

Measure = 
var _col=MAX('Table'[col])
var _col2=MAX('Table'[col2])
return 
SWITCH(TRUE(),
    _col="short"&&_col2>0,2,
    _col="short"&&_col2<>0,1,
    _col="long"&&_col2>0,1,
    _col="long"&&_col2<>0,2,
    2
)

 

If it doesn't work, pelase share your sample data and expected result in excel.

Best Regards,
Community Support Team _ Eason

tamerj1
Community Champion
Community Champion

Hi @fisqkuz1 
I don't fully understand your If - Else statement but you may try the following

Revenue or Cost =
SUMX (
    table,
    IF (
        table[col] = "short" & table[col2] > 0,
        2,
        IF ( table[col] = "long" & table[col2] > 0, 1, 2 )
    )
)

hi, thanks for your answer!

i want to simply get a 1 or 2 as output such as booleans

where 1 = revenue and 2 = cost

 

tamerj1
Community Champion
Community Champion

The you use the sane logic. Only last oart shall not be required 

Revenue or Cost =
SUMX (
    table,
    IF (
        table[col] = "short" & table[col2] > 0,
        table[Revenue],
        IF ( table[col] = "long" & table[col2] > 0, table[Cost] )
    )
)

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.