Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Need help with Data Cleansing

Hey guys,

I need to do some data cleansing and I'm not really sure if this topic needs to be posted here at Power Query or at Dax.
I have a table containing the following columns:
Personeel.In-/Extern
Uren Registratie 2.CategorieID
WBS Code
Klantnum.

I need to 'overwrite' the value of Uren Registratie 2.CategorieID (which is 1) with the following logic:
IF Personeel.In-/Extern = "Extern" AND
WBS Code = "731/7011.01" AND
Klantnum. is empty
THEN 
Uren Registratie 2.CategorieID = 6

Should I do this in Power Query or use Dax?
How can I do this?

With kind regards,

Lazzanova


1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

For overwriting the values, DAX can't be used. For this purpose, you will need to use PQ.

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcq0oSS3KU9JRMgJic2NDfXMDQ0M9IAZyDZVidXCrAPLA8okpKSlAtjFI1ghZ1ggsbWIMhECeCYZuI0LGA+2PBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Personeel.In-/Extern" = _t, #"Uren Registratie 2.CategorieID" = _t, #"WBS Code" = _t, #"Klantnum." = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Personeel.In-/Extern", type text}, {"Uren Registratie 2.CategorieID", Int64.Type}, {"WBS Code", type text}, {"Klantnum.", Int64.Type}}),
    Custom1 = Table.ReplaceValue(#"Changed Type", each [Uren Registratie 2.CategorieID], each if  [#"Personeel.In-/Extern"] = "Extern" and [WBS Code] = "731/7011.01" and [#"Klantnum."] =null then 6 else [Uren Registratie 2.CategorieID], Replacer.ReplaceValue,{"Uren Registratie 2.CategorieID"})
in
    Custom1

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

You are totally right... Best close this topic before I feel more ashamed 😄
Anyway Vijay thank you very much for your time! Much appreciated!

Vijay_A_Verma
Super User
Super User

For overwriting the values, DAX can't be used. For this purpose, you will need to use PQ.

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcq0oSS3KU9JRMgJic2NDfXMDQ0M9IAZyDZVidXCrAPLA8okpKSlAtjFI1ghZ1ggsbWIMhECeCYZuI0LGA+2PBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Personeel.In-/Extern" = _t, #"Uren Registratie 2.CategorieID" = _t, #"WBS Code" = _t, #"Klantnum." = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Personeel.In-/Extern", type text}, {"Uren Registratie 2.CategorieID", Int64.Type}, {"WBS Code", type text}, {"Klantnum.", Int64.Type}}),
    Custom1 = Table.ReplaceValue(#"Changed Type", each [Uren Registratie 2.CategorieID], each if  [#"Personeel.In-/Extern"] = "Extern" and [WBS Code] = "731/7011.01" and [#"Klantnum."] =null then 6 else [Uren Registratie 2.CategorieID], Replacer.ReplaceValue,{"Uren Registratie 2.CategorieID"})
in
    Custom1
Anonymous
Not applicable

The code you've posted here results in this query:

LaZZaNoVa61_0-1657276360076.png

Not really sure why these values exist.

My source is a sample one, just for example. I need some sample data from your side to check on this. Also point out which value should have changed. 

Anonymous
Not applicable

Here is some sample data. I've deleted other columns.
See row 17: The value of 1 needs to change to 6.
(Because Klantnum. = empty / null) and WBS Code = 713/7011.01 and Personeel.In-/Extern = Extern (It shows null in PQ)


Row Nr.Klantnum.Personeel.NaamWBS CodeUren Registratie 2.CategorieIDPersoneel.In-/Extern
11305030220Önder Kandemir713/7011.011Extern
21305030211Önder Kandemir713/7011.011Extern
31305030177Önder Kandemir713/7011.011Extern
41305030228Önder Kandemir713/7011.011Extern
51305030178Önder Kandemir713/7011.011Extern
61305030019Önder Kandemir713/7011.011Extern
71305030024Önder Kandemir713/7011.011Extern
81305030195Önder Kandemir713/7011.011Extern
91305030229Önder Kandemir713/7011.011Extern
101305030120Önder Kandemir713/7011.011Extern
111301020560Önder Kandemir713/7011.011Extern
121305030171Önder Kandemir713/7011.011Extern
131305030018Önder Kandemir713/7011.011Extern
141305030120Önder Kandemir70406Extern
151305030120Önder Kandemir70053Extern
161305030191Önder Kandemir713/7011.011Extern
17 Önder Kandemir713/7011.011Extern
18 Önder Kandemir70453Extern
19 Önder Kandemir70053Extern

 

In your original requirement, you gave WBS Code=731/7011.01 whereas in your table, value is 713 not 731....Hence, in the code also, you will need to replace 731/7011.01 with 713/7011.01. Hence, following would work

= Table.ReplaceValue(#"Added Custom", each [Uren Registratie 2.CategorieID], each if [#"Personeel.In-/Extern"] = "Extern" and [WBS Code] = "713/7011.01" and [#"Klantnum."] =null then 6 else [Uren Registratie 2.CategorieID], Replacer.ReplaceValue,{"Uren Registratie 2.CategorieID"})

 

Anonymous
Not applicable

Hey Vijay,

Thanks for the quick response. I tried doing what you have suggested, but failed in doing so.
But I did try adding another step in PQ:

LaZZaNoVa61_0-1657270353642.png


I've copy pasted then the last part of your code:
= Table.ReplaceValue(#"Namen van kolommen gewijzigd2", each [Uren Registratie 2.CategorieID], each if [#"Personeel.In-/Extern"] = "Extern" and [WBS Code] = "731/7011.01" and [#"Klantnum."] =null then 6 else [Uren Registratie 2.CategorieID], Replacer.ReplaceValue,{"Uren Registratie 2.CategorieID"})

I thought this would change the values of the table of the previous step, but it didn't. What am I doing wrong here?

With kind regards,

Lazzanova

I am not sure whether your Klantnum. column is null or blanks. You can try following

= Table.ReplaceValue(#"Namen van kolommen gewijzigd2", each [Uren Registratie 2.CategorieID], each if [#"Personeel.In-/Extern"] = "Extern" and [WBS Code] = "731/7011.01" and ([#"Klantnum."] =null or [#"Klantnum."] ="") then 6 else [Uren Registratie 2.CategorieID], Replacer.ReplaceValue,{"Uren Registratie 2.CategorieID"})
Anonymous
Not applicable

The column has nulls, so the previous code would be correct. However, upon checking if the values have changed, I don't see any changes made. 
If I would have had a typo regarding the column names, an error message would appear.
But that is also not the case. I can't explain why the values are not changing.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors