Forum Discussion
Convert kg, tons, lbs in new measure with Switch function
- 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
- 3 years ago
I'm enable to updload a pbix for some reason - but please see link here to my google drive: https://drive.google.com/file/d/1fF-qCpz3HXZRLTkTlgHyjpr-H14JmuHn/view?usp=sharing
Thank you
Hi Chaithanya
Another solution could be to create a many to many reference table which you join to the data table
Join using Base Unit to the main table:
If you create a filter based on "preffered unit" and set it to one selected value - this means that for every value of base unit, there is only one corresponding row in the rerference table.
The expression is then:
The advantage of this is more flexibility, should you wish to add more conversions.
Pi
I'm enable to updload a pbix for some reason - but please see link here to my google drive: https://drive.google.com/file/d/1fF-qCpz3HXZRLTkTlgHyjpr-H14JmuHn/view?usp=sharing
Thank you