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.
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:
Quantity | Unit | KG/M3 |
125.2 | KG | 125.2 |
1023.1 | LB | 464.070 |
33 | M3 | 33 |
1234 | CF | 34.943 |
0 | KG | 0 |
0 | LB | 0 |
0 | M3 | 0 |
0 | CF | 0 |
Could you please have a look at this pbix: https://ufile.io/mfspjog4
Appreciated any help provided.
Solved! Go to 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 () ) |
Best Regards
@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 () ) |
Best Regards
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.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
112 | |
97 | |
85 | |
67 | |
59 |
User | Count |
---|---|
150 | |
120 | |
100 | |
87 | |
68 |