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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
kevinsray
Helper II
Helper II

IF ELSE to DAX

Hi all,

I am really having trouble getting the following formula to work in DAX.

If TABLEA.CHECK = "Y" THEN QTY = TABLEB.QTY * TABLEA.PerCarton
ELSE
QTY = TABLEB.QTY

 

TABLEA.CHECK is Text.

TABLEA.PerCarton is a number.

TABLEB.QTY is a number.

There is a 1 to many relationship on TABLEA.STOCKCODE to TABLEB.STOCKCODE (both Text)

 

If anyone is able to give any advice it would be greatly appreciated.

1 ACCEPTED SOLUTION
AkhilAshok
Solution Sage
Solution Sage

There are multiple ways you can do this with measure. An easy way is as below:

 

Total Quantity =
SUMX (
    TABLEB,
    IF (
        RELATED ( TABLEA[CHECK] ) = "Y",
        TABLEB[QTY] * RELATED ( TABLEA[PerCarton] ),
        TABLEB[QTY]
    )
)

 

View solution in original post

2 REPLIES 2
AkhilAshok
Solution Sage
Solution Sage

There are multiple ways you can do this with measure. An easy way is as below:

 

Total Quantity =
SUMX (
    TABLEB,
    IF (
        RELATED ( TABLEA[CHECK] ) = "Y",
        TABLEB[QTY] * RELATED ( TABLEA[PerCarton] ),
        TABLEB[QTY]
    )
)

 

Thank you very much.
This worked perfected. RELATED was the function which I needed...

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.