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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
andfx
Frequent Visitor

IF Condition

Hi guys,

 

I would like to know if it's possible to do what I'm trying to do in Power BI. It must check conditions and based on it tell something about that comparision. Using excel is really easy to do that, just an If.

 

I'm planing to make a comparission tool.

 

 

 

Thank you,

Anderson.

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @andfx 

Try this, where Table1 is the table you show:

1. Create a calculated one-column table that we will use to select the second name:

      AuxTable = ALL(Table1[Name])

2. Place two slicers in your report, one with Table1[Name] and the other one with the created  AuxTable[Name]

3. Create this measure and place it in a card

 

 

Measure =
VAR _Name1 =
    SELECTEDVALUE ( Table1[Name] )
VAR _Name2 =
    SELECTEDVALUE ( AuxTable[Name] )
VAR _Age1 =
    SELECTEDVALUE ( Table1[Age] )
VAR _Age2 =
    LOOKUPVALUE ( AuxTable[Age], AuxTable[Name], _Name2 )
VAR _SameAge = Age1 = _Age2
VAR _Eldest =
    IF ( _Age1 > _Age2, _Name1, _Name2 )
VAR _Youngest =
    IF ( _Age1 < _Age2, _Name1, _Name2 )
VAR _SameAgeMsg = _Name1 & " and " & _Name2 & " have the same age"
VAR _DiffAgeMsg = _Eldest & " is older than " & _Youngest
RETURN
    IF ( _SameAge, _SameAgeMsg, _DiffAgeMsg )

 

You can also take pieces of that measure to create other measures that display the the ages as you show them.

 

 

 

    

 

View solution in original post

1 REPLY 1
AlB
Community Champion
Community Champion

Hi @andfx 

Try this, where Table1 is the table you show:

1. Create a calculated one-column table that we will use to select the second name:

      AuxTable = ALL(Table1[Name])

2. Place two slicers in your report, one with Table1[Name] and the other one with the created  AuxTable[Name]

3. Create this measure and place it in a card

 

 

Measure =
VAR _Name1 =
    SELECTEDVALUE ( Table1[Name] )
VAR _Name2 =
    SELECTEDVALUE ( AuxTable[Name] )
VAR _Age1 =
    SELECTEDVALUE ( Table1[Age] )
VAR _Age2 =
    LOOKUPVALUE ( AuxTable[Age], AuxTable[Name], _Name2 )
VAR _SameAge = Age1 = _Age2
VAR _Eldest =
    IF ( _Age1 > _Age2, _Name1, _Name2 )
VAR _Youngest =
    IF ( _Age1 < _Age2, _Name1, _Name2 )
VAR _SameAgeMsg = _Name1 & " and " & _Name2 & " have the same age"
VAR _DiffAgeMsg = _Eldest & " is older than " & _Youngest
RETURN
    IF ( _SameAge, _SameAgeMsg, _DiffAgeMsg )

 

You can also take pieces of that measure to create other measures that display the the ages as you show them.

 

 

 

    

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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

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.