Forum Discussion
Divide specific ratio if value starts with
I have two tables showing the value of items and ratio to be divided. How to create a new table showing the divided values by the product code?
Table 1:
Table 2:
Expected table output:
Any help given is much appreciated. Thank you.
- Anonymous4 years ago
Hi Anonymous ,
you can create a calculated column using the following DAXNew Value(value/ratio) = DIVIDE( 'Table 1'[Value], LOOKUPVALUE( 'Table 2'[Ratio], 'Table 2'[Product Code], LEFT('Table 1'[Item],2) ) )Regards
Anonymous ,
Step 1: First create the relationship between this 2 tables by creating Product Code calculated column in Ratio table,
Product Code = LEFT(Ratio[Item],2)Step 2: Then create the relationship between them as per the below image,
Step 3: Lastly you can create the new table by using the below code,
New Value Table = SELECTCOLUMNS(Ratio,"Item",Ratio[Item],"New Value",DIVIDE(Ratio[Value],RELATED('Product deatails ratio'[Ratio])))Thanks,
Arul
- Anonymous4 years ago
If you want the result in a new table, you can use
Table 3 = SELECTCOLUMNS( 'Table 1', "Item",'Table 1'[Item], "New Value(value/ratio)", DIVIDE( 'Table 1'[Value], LOOKUPVALUE( 'Table 2'[Ratio], 'Table 2'[Product Code], LEFT('Table 1'[Item],2) ) ) )Regards
Hi Anonymous
Assuming relationship is useless in this case and that you are looking for a calculated column then you can try
New Value = VAR CurrentValue = Table1[Value] VAR Ratio = CALCULATE ( VALUES ( Table2[Ratio] ), FILTER ( Table2, CONTAINSSTRING ( Table1[Item], Table2[Product code] ) ) ) RETURN DIVIDE ( CurrentValue, Ratio )
5 Replies
- Arul
Super User
Anonymous ,
Do you have any other relationship column between this two tables?
- AnonymousNot applicable
Hi Anonymous ,
you can create a calculated column using the following DAXNew Value(value/ratio) = DIVIDE( 'Table 1'[Value], LOOKUPVALUE( 'Table 2'[Ratio], 'Table 2'[Product Code], LEFT('Table 1'[Item],2) ) )Regards
- AnonymousNot applicable
If you want the result in a new table, you can use
Table 3 = SELECTCOLUMNS( 'Table 1', "Item",'Table 1'[Item], "New Value(value/ratio)", DIVIDE( 'Table 1'[Value], LOOKUPVALUE( 'Table 2'[Ratio], 'Table 2'[Product Code], LEFT('Table 1'[Item],2) ) ) )Regards
- Arul
Super User
Anonymous ,
Step 1: First create the relationship between this 2 tables by creating Product Code calculated column in Ratio table,
Product Code = LEFT(Ratio[Item],2)Step 2: Then create the relationship between them as per the below image,
Step 3: Lastly you can create the new table by using the below code,
New Value Table = SELECTCOLUMNS(Ratio,"Item",Ratio[Item],"New Value",DIVIDE(Ratio[Value],RELATED('Product deatails ratio'[Ratio])))Thanks,
Arul
- tamerj1
Community Champion
Hi Anonymous
Assuming relationship is useless in this case and that you are looking for a calculated column then you can try
New Value = VAR CurrentValue = Table1[Value] VAR Ratio = CALCULATE ( VALUES ( Table2[Ratio] ), FILTER ( Table2, CONTAINSSTRING ( Table1[Item], Table2[Product code] ) ) ) RETURN DIVIDE ( CurrentValue, Ratio )