0

I am working on a Power BI report. There are two dimensions DimWorkedClass and DimWorkedService. (The above snippet is obtained by exporting matrix values to csv.)

The requirement is to transform only the Worked Service Text5 into the Worked Class of Text5 as opposed to A (which is the current value).

It can be transformed at the backend, but is there any way to do it in Power BI?

Please see the image here

Alexis Olson
  • 38,724
  • 7
  • 42
  • 64
Spartan567
  • 41
  • 7
  • So in this example, you want to replace `A` with `text5` only in the highlighted row? – Alexis Olson Sep 18 '18 at 16:07
  • Yea, meaning I want the value under Worked Class to be reflected as "text5" wherever there is Worked Service of "text5" – Spartan567 Sep 18 '18 at 16:09
  • Please avoid *"Give me the codez"* questions. Instead show the script you are working on and state where the problem is. Also see [How much research effort is expected of Stack Overflow users?](http://meta.stackoverflow.com/q/261592/608639) – jww Sep 19 '18 at 00:21

1 Answers1

0

This is trickier than it might appear, but it looks like this question has already been answered here:

Power Query Transform a Column based on Another Column

In your case, the M code would look something like this:

= Table.FromRecords(Table.TransformRows(#"[Source or Previous Step Here]",
      (here) => Record.TransformFields(here, {"Worked Class",
          each if here[Worked Service] = "text5" then "text5" else here[Worked Class]})))

(In the above, here represents the current row.)

Another answer points out a slightly cleaner way of doing this:

= Table.ReplaceValue(#"[Source or Previous Step Here]",
      each [Worked Class],
      each if [Worked Service] = "text5" then "text5" else [Worked Class],
      Replacer.ReplaceText,{"Worked Class"})
Alexis Olson
  • 38,724
  • 7
  • 42
  • 64