cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
AlexaderMilland
Helper III
Helper III

Divide every row with a specific row

I have a big exchange rate table, unfortunately all the numbers are from EUR to XXX currency.

I would like to alter it to be from DKK to XXX currency, and would be simple just to divide all the Rates by the Rate that is in the DKK row.

So how do i divide all the 31 rows af "Rate" with the value in row 5 (Also given that it might not always be row 5, but always be the row with To = "DKK" value?

AlexaderMilland_1-1664443284522.png

 

I found a solution using merge queries and some inverse logic with joins, but seems super convoluted for something so simple. 

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

You can get the value by first using Table.SelectRows (you don't need to write this yourself, you can filter from the column header to get the right syntax).

This returns a table.  You then put the name of the column after it like TableSelectRows(...........[Rate]

This will return a column.  Now, even though it's a single column from a single row, we need to get the first value with List.First()

That's one algorithm to do it and you may need to put part of it in a variable to multiply each row by it.

See how you get on.

View solution in original post

2 REPLIES 2
HotChilli
Super User
Super User

You can get the value by first using Table.SelectRows (you don't need to write this yourself, you can filter from the column header to get the right syntax).

This returns a table.  You then put the name of the column after it like TableSelectRows(...........[Rate]

This will return a column.  Now, even though it's a single column from a single row, we need to get the first value with List.First()

That's one algorithm to do it and you may need to put part of it in a variable to multiply each row by it.

See how you get on.

 

I got it to work with your logic, although i guess I used quite a bit more steps than necessary

 

let
Source = Xml.Tables(Web.Contents("https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml?c57b0ed41402673d8e5e11424e48bee2")),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"subject", type text}}),
#"http://www ecb int/vocabulary/2002-08-01/eurofxref" = #"Changed Type"{0}[#"http://www.ecb.int/vocabulary/2002-08-01/eurofxref"],
Cube = #"http://www ecb int/vocabulary/2002-08-01/eurofxref"{0}[Cube],
Cube1 = Cube{0}[Cube],
#"Changed Type1" = Table.TransformColumnTypes(Cube1,{{"Attribute:time", type date}}),
Cube2 = #"Changed Type1"{0}[Cube],
#"Replaced Value" = Table.ReplaceValue(Cube2,".",",",Replacer.ReplaceText,{"Attribute:rate"}),
#"Changed Type2" = Table.TransformColumnTypes(#"Replaced Value",{{"Attribute:rate", type number}}),
#"Added Custom" = Table.AddColumn(#"Changed Type2", "From", each "EUR"),
#"Renamed Columns" = Table.RenameColumns(#"Added Custom",{{"Attribute:currency", "To"}, {"Attribute:rate", "Rate"}}),
#"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns",{"Rate", "From", "To"}),
#"Changed Type3" = Table.TransformColumnTypes(#"Reordered Columns",{{"From", type text}}),
#"Insert Rows" = Table.InsertRows(#"Changed Type3",0,{[Rate = 1, From = "EUR", To = "EUR"]}),
#"Custom Function" = Table.AddColumn(#"Insert Rows","RateInverse", each Table.SelectRows(#"Insert Rows",each [To]="DKK")),
#"Expanded RateInverse" = Table.ExpandTableColumn(#"Custom Function", "RateInverse", {"Rate"}, {"Rate.1"}),
#"Added Custom1" = Table.AddColumn(#"Expanded RateInverse", "RateDKK", each [Rate]/[Rate.1]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Rate", "Rate.1"}),
#"Replaced Value1" = Table.ReplaceValue(#"Removed Columns","EUR","DKK",Replacer.ReplaceText,{"From"}),
#"Added Custom2" = Table.AddColumn(#"Replaced Value1", "Custom", each 1/[RateDKK]),
#"Renamed Columns2" = Table.RenameColumns(#"Added Custom2",{{"RateDKK", "Rate"}, {"Custom", "RateInverse"}}),
#"Changed Type4" = Table.TransformColumnTypes(#"Renamed Columns2",{{"RateInverse", type number}, {"Rate", type number}})
in
#"Changed Type4"

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors