Forum Discussion
Multiply with difference columns based on a value
I have a query which need to multiply wiith different columns based on a column "Duration". Formula like this:
when duration is 1, I need to multiply commission amount, exchange rate and 1st year.
when duration is 2, multiply commission amount, exchange rate and 2nd year.
when duration is 3, multiply commission amount, exchange rate and 3rd year.
when duration is 4, multiply commission amount, exchange rate and 4th year.
etc...
Is there any formula or method could help?
I have made a calculated column in the Power BI level. If you want to make this in Power Query then write the code like this..
The result will be something like this..
9 Replies
- Angith_NairContinued Contributor
Hi Anonymous ,
Could you please provide some sample data so as to understand it more clearly..?
- AnonymousNot applicable
like this!
- Angith_NairContinued Contributor
Try to unpivot the year columns in Power Query level. After unpivoting the table will look like this..
Then in Power BI try to create a calculated column like this:
Column = IF ( SELECTEDVALUE ( 'Table'[Duration] ) = SELECTEDVALUE ( 'Table'[Year] ), 'Table'[Commission Amount] * 'Table'[Exchange Rate] * 'Table'[Values], 0 )which will give you the result...
If this helps, kindly mark this as a solution. Appreciate with Kuddos. Thank You..
- SmauroSolution Sage
Hi Anonymous
You could try adding this as a step, it skips unpivoting and just selects the correct column:
= letYearColumns = List.Select(Table.ColumnNames(#"Removed Columns"),each Text.EndsWith(_, "year"))inTable.AddColumn(#"Removed Columns", "New Column",each [Commission Amount] * [#"Exchange Rate (History)"] *Record.FieldOrDefault(_, (List.Select(YearColumns,(t) => Number.From(Text.Select(t, {"0".."9"})) = [Duration] ){0}?)??"" ),type number)Cheers
- Syndicate_AdminAdministrator
Hi @KLee1024
You could try adding this as a step, it skips unpivoting and just selects the correct column:
= letYearColumns = List.Select(Table.ColumnNames(#"Removed Columns"),each Text.EndsWith(_, "year"))inTable.AddColumn(#"Removed Columns", "New Column",each [Commission Amount] * [#"Exchange Rate (History)"] *Record.FieldOrDefault(_, (List.Select(YearColumns,(t) => Number.From(Text.Select(t, {"0".."9"})) = [Duration] ){0}?)??"" ),type number)Cheers