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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
NickProp28
Post Partisan
Post Partisan

Coding checking and request help to multiple to value

Dear Community, 

 

I have two table and applied lookupvalue to get the information.

Condition:
If Unit is KG or LB, vlookup and return the KG rate.

If Unit is M3 or CF, vlookup and return the M3 rate.

Am I right if the DAX code is in this way? Just want double confirm on it

KG/M3 = Switch(True(),
(Main[Unit]= "KG" || Main[Unit] = "LB") , LOOKUPVALUE(Table1[Rate],Table1[From_Unit],Main[Unit],Table1[To_Unit],"KG"),

(Main[Unit] ="M3" || Main[Unit] = "CF") , LOOKUPVALUE(Table1[Rate],Table1[From_Unit],Main[Unit],Table1[To_Unit],"M3"),
BLANK())

Furthermore, I would like to modify the DAX code (No idea how to apply to calculation after the conditional statement). Instead showing the rate, I want the final calculation of multiply rate and quatity.

Expected value:

QuantityUnitKG/M3
125.2KG125.2
1023.1LB464.070
33M333
1234CF34.943
0KG0
0LB0
0M30
0CF0

 

Could you please have a look at this pbix: https://ufile.io/mfspjog4

Appreciated any help provided. 

1 ACCEPTED SOLUTION

Hi @NickProp28 ,

You can update the formula of your calculated column [KG/M3] as below, the part with red font is new added:

KG/M3 =
SWITCH (
    TRUE (),
     ( Main[Unit] = "KG"
        || Main[Unit] = "LB" ),
        LOOKUPVALUE (
            Table1[Rate],
            Table1[From_Unit], Main[Unit],
            Table1[To_Unit], "KG"
        ) * 'Main'[Quantity],
     ( Main[Unit] = "M3"
        || Main[Unit] = "CF" ),
        LOOKUPVALUE (
            Table1[Rate],
            Table1[From_Unit], Main[Unit],
            Table1[To_Unit], "M3"
        ) * 'Main'[Quantity],
    BLANK ()
)

rate multiply quanitity..JPG

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@NickProp28 , Are you trying move data from one table to another?

Check if this video can help how to do -https://www.youtube.com/watch?v=czNHt7UXIe8

Dear @amitchandak ,

 

No Sir, 

I want to include the calculation part in SWITCH after return the rate. 

For example, 

(Main[Unit]= "KG" || Main[Unit] = "LB") , LOOKUPVALUE(Table1[Rate],Table1[From_Unit],Main[Unit],Table1[To_Unit],"KG"), Quantity * KG/M3 

 * I know can simply open another new column and perform the calculation. But would like to ask is it possible to do it in SWITCH.

Hi @NickProp28 ,

You can update the formula of your calculated column [KG/M3] as below, the part with red font is new added:

KG/M3 =
SWITCH (
    TRUE (),
     ( Main[Unit] = "KG"
        || Main[Unit] = "LB" ),
        LOOKUPVALUE (
            Table1[Rate],
            Table1[From_Unit], Main[Unit],
            Table1[To_Unit], "KG"
        ) * 'Main'[Quantity],
     ( Main[Unit] = "M3"
        || Main[Unit] = "CF" ),
        LOOKUPVALUE (
            Table1[Rate],
            Table1[From_Unit], Main[Unit],
            Table1[To_Unit], "M3"
        ) * 'Main'[Quantity],
    BLANK ()
)

rate multiply quanitity..JPG

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @NickProp28 ,

I have checked your file. And you can use switch.

I created two new columns without switch or if and they giving values as an individual, which gets merged because of the switch in your column.

At a high level, the approach seems fine. Unless there some issue you are facing.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.