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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

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?

1 ACCEPTED SOLUTION

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..

Angith_Nair_0-1616568955344.png

The result will be something like this..

Angith_Nair_0-1616569403682.png

 

 

View solution in original post

9 REPLIES 9
Syndicate_Admin
Administrator
Administrator

Hi @KLee1024 

 

You could try adding this as a step, it skips unpivoting and just selects the correct column:

 

let
    YearColumns = List.Select(
        Table.ColumnNames(#"Removed Columns"),
        each Text.EndsWith(_, "year"))
in
    Table.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

Smauro
Solution Sage
Solution Sage

Hi @Anonymous 

 

You could try adding this as a step, it skips unpivoting and just selects the correct column:

 

let
    YearColumns = List.Select(
        Table.ColumnNames(#"Removed Columns"),
        each Text.EndsWith(_, "year"))
in
    Table.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




Spyros Mavroforos

Data Consultant


Find me on LinkedIn or drop me an email

eSpyros

Angith_Nair
Continued Contributor
Continued Contributor

Hi @Anonymous ,

Could you please provide some sample data so as to understand it more clearly..? 

Anonymous
Not applicable

1.png

 like this!

Try to unpivot the year columns in Power Query level. After unpivoting the table will look like this..

Angith_Nair_0-1616561521259.png

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...

Angith_Nair_1-1616561654765.png

If this helps, kindly mark this as a solution. Appreciate with Kuddos. Thank You..

Anonymous
Not applicable

Thank you so much for your help! But I can't use IF in the formula...

2.png

Anonymous
Not applicable

That's work! Really thankssss!!!

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..

Angith_Nair_0-1616568955344.png

The result will be something like this..

Angith_Nair_0-1616569403682.png

 

 

Anonymous
Not applicable

Hi sorry, can I have one more question?

 

As I was merged table for the exchange rate which have few months data when I unpivot the year the result will calculated all months of exchange rate for 1 case but I only want when 1 case appear then calculate the correct formula [amount * exchange rate * value].

 

I don't know do you understand me....haha....but thanks anyway!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.