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.
Hello,
The following will be an example of my problem.
Here are the data :
I want to filter these data by type of stock so I unpivot the column related to the stock number, and we obtain this table :
Only values different to 0 are interesting in the "Valeur" column consequently that's the result :
My problem it's the following, I want to replace some value by 0 depending condition.
For exemple let's focus on the second article:
I want to replace cupboard 1 stock value by 0 when modality in "Attribut" column equal "Freezer stock" for the first line, and replace Freezer stock value by 0 when modality = "cupboard 1 stock" for the second line. I want there to be only the value for the stock concerned and not another value for another type of stock that is different to the type of stock entered on the line. And that's for all line and all column concern value of stock.
I have try to write with a M request but it doesn't work.
Someone can help me please !!!
Solved! Go to Solution.
Hi @Imad-R,
See if the code below works as you want. You can then modified to suite your case:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wck7MTlXSUTIEYrei1NQqpVgdFEHXnOJUpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Value = _t, Attribute = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Value", Int64.Type}, {"Attribute", type text}}),
#"Replaced Value" = Table.ReplaceValue(#"Changed Type",each [Attribute], null, (x, y, z)=> if y= "Freez" then 0 else x,{"Value"})
in
#"Replaced Value"
Cheers,
John
Hi @Imad-R,
See if the code below works as you want. You can then modified to suite your case:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wck7MTlXSUTIEYrei1NQqpVgdFEHXnOJUpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Value = _t, Attribute = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Value", Int64.Type}, {"Attribute", type text}}),
#"Replaced Value" = Table.ReplaceValue(#"Changed Type",each [Attribute], null, (x, y, z)=> if y= "Freez" then 0 else x,{"Value"})
in
#"Replaced Value"
Cheers,
John
Hello,
Thanks, it's working. It is not very convenient because I must make 3 different M requests for each modality of Attribut column but it suits me.
Thanks for your reactivity !
-- 1
= Table.ReplaceValue(#"Lignes filtrées",each [Attribut], null, (x, y, z)=> if y = "Freezer stock" then 0 else x,{"cupboard 1 stock value", "cupboard 2 stock value"})
-- 2
= Table.ReplaceValue(#"Personnalisé1",each [Attribut], null, (x, y, z)=> if y = "cupboard 1 stock" then 0 else x,{"Freezer stock value", "cupboard 2 stock value"})
-- 3
= Table.ReplaceValue(#"Personnalisé2",each [Attribut], null, (x, y, z)=> if y = "cupboard 2 stock" then 0 else x,{"Freezer stock value", "cupboard 1 stock value"})
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 |
---|---|
14 | |
13 | |
10 | |
8 | |
7 |
User | Count |
---|---|
17 | |
11 | |
7 | |
6 | |
6 |