Forum Discussion

Chaithanya89's avatar
Chaithanya89
Frequent Visitor
3 years ago
Solved

Convert kg, tons, lbs in new measure with Switch function

Dear Community,   I have a table which consists of 2 column with weight and respective weight units either KG or LB. And would like get help on DAX to create a new column measure which calculate al...
  • danextian's avatar
    3 years ago

    Hi Chaithanya89 ,

     

    There are several approaches to this problem. You can use SWITCH or field parameters. For the former, you need to create a disconnected table (without relationship to fact table) that will serve as holder of the switch measure. Please see sample DAX formulas below:

    Base Unit Table = 
    DATATABLE ( "Unit", STRING, "Sort", INTEGER, { { "lbs", 1 }, { "tonnes", 2 } } )
    
    lbs or tonnes = 
    SWITCH (
        SELECTEDVALUE ( BaseUnit[Unit] ),
        "lbs", [Quantity (lbs)],
        "tonnes", [Quantity (tonnes)]
    )
    

     

    Please see attached pbix for the details