Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi,
I am trying to find and replace values for all the date columns ranging from Jan 2019 to Dec 2024.
I am doing some transformation using if condition, like first select the condition from another column and if it matches multiply the values in the column with multiplier column and 1000 else keep them as is and replace the values in existing column. Below is the m code that works only for single column.
</> #"Replaced Value3" = Table.ReplaceValue(#"Changed Type3",each [#"May-2020"], each if [Impact Type] = "One-off costs ($m)" then [Multiplier] * [#"May-2020"] * 1000 else [#"May-2020"] ,Replacer.ReplaceValue,{"May-2020"}) </>
How can I use this single step for all the columns like this so then I can use the transformations for all the columns in a single go:
</> #"Replaced Value3" = Table.ReplaceValue(#"Changed Type3", each {"Jan-2020", "Feb-2020", "Mar-2020", "Apr-2020", "May-2020"}, each if [Impact Type] = "One-off costs ($m)" then [Multiplier] * {"Jan-2020", "Feb-2020", "Mar-2020", "Apr-2020", "May-2020"} * 1000 else {"Jan-2020", "Feb-2020", "Mar-2020", "Apr-2020", "May-2020"} ,Replacer.ReplaceValue,{"Jan-2020", "Feb-2020", "Mar-2020", "Apr-2020", "May-2020"}) </>
The Multiplier and Impact type looks like this,
The transformation can be seen below, I want the same for all the columns that is for May-2020, just use multiplier and condition followed by multiply by 1000.
Can someone please help as I am stuck on this one for a long time now. Many Thanks!
Please let me know where I can clarify further.
@amitchandak @Greg_Deckler @AlexisOlson
Solved! Go to Solution.
Hi @Anonymous ,
Multi-select (Ctrl+click) all colums that are not your date columns.
Go to Transform tab > Unpivot Columns > Unpivot Other Columns.
Perform your replace function on the new [Value] field.
Re-pivot [Attribute] column using [Value] as population field if you want *.
* As a side note, the data structure after you have done the first Unpivot operation is the generally-accepted correct data structure. Having separate columns for each date is unwieldy and will not scale well. Additionally, the structure you currently have will make it very difficult to create relationships and write measures.
Pete
Proud to be a Datanaut!
Hi @Anonymous ,
Multi-select (Ctrl+click) all colums that are not your date columns.
Go to Transform tab > Unpivot Columns > Unpivot Other Columns.
Perform your replace function on the new [Value] field.
Re-pivot [Attribute] column using [Value] as population field if you want *.
* As a side note, the data structure after you have done the first Unpivot operation is the generally-accepted correct data structure. Having separate columns for each date is unwieldy and will not scale well. Additionally, the structure you currently have will make it very difficult to create relationships and write measures.
Pete
Proud to be a Datanaut!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
9 | |
8 | |
7 | |
6 | |
6 |
User | Count |
---|---|
12 | |
11 | |
9 | |
6 | |
6 |