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

3
  • So in this example, you want to replace A with text5 only in the highlighted row? Commented Sep 18, 2018 at 16:07
  • Yea, meaning I want the value under Worked Class to be reflected as "text5" wherever there is Worked Service of "text5" Commented Sep 18, 2018 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? Commented Sep 19, 2018 at 0:21

1 Answer 1

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"})
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, Alexis. May I know what source refers to in "[Source or Previous Step Here]" ?
The Source is where your data table comes from and is typically the first step in the query.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.