Forum Discussion
Checking if right code was deleted
The column 1 codes are taken into account through the relationship. Also, I saw in the first example rows had Code1 in the first value and for the deletion, and then Code2 for the new/correct one. I assumed (perhaps incorrectly) that it was a typo on the second set of example rows did not have 1 or 2 next to the codes. Please confirm my assumption was incorrect, and I can propose a different measure.
Regards,
Pat
mahoneypat Thanks! Forgot to mention it will be a many to many relationship if I do it that way. See below.
- mahoneypat6 years agoMicrosoft Employee
I'm assuming there is some DateTime column or something to differentiate which Code came first (one sequence is correct, the other incorrect). If so, you can use that column. If not, I made an Index column in the query editor on your table and was able to detect the missed deletion with this column expression. No relationship to the other table required.
Missed Deletion = VAR __index = MIN ( Codes[Index] ) VAR __badcode = CALCULATE ( MIN ( BadCombos[Column2] ), BadCombos[Column1] = EARLIER ( Codes[Data] ) ) RETURN IF ( NOT ( ISBLANK ( __badcode ) ), IF ( CALCULATE ( COUNTROWS ( Codes ), ALLEXCEPT ( Codes, Codes[ID] ), Codes[Index] > __index, Codes[Data] = __badcode ) > 0, "Missed Deletion" ) )If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
- mahoneypat6 years agoMicrosoft Employee
I didn't make the index column with DAX. I did it in the query editor using the button on the Add Column tab. Here is the M code, but it is just simple index column addition.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXLOT0k1BNL+RZnpmXmJOUCmEQgoxeqgKnBJzUktSQUyUGSMULUagwBYgRN2s01AAEMBqtlO2M02BAGl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Item = _t, Operation = _t, Data = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Item", type text}, {"Operation", type text}, {"Data", Int64.Type}}), #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1) in #"Added Index"If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
- mahoneypat6 years agoMicrosoft Employee
So do the data have Code1, Code2? If not, is there some way to differentiate the intial code vs the replacement code? DateTime column? Or is any combination of the two codes in either order always an error?
Regards,
Pat
- PowerBI1234566 years agoPost Partisan
mahoneypat no the data does not have Code 1, Code 2. I think your code is right, but I can't create a relationship since its many to many.
- PowerBI1234566 years agoPost Partisan
mahoneypat Would you be able to provide a sample file so I can take a look?
- PowerBI1234566 years agoPost Partisan
mahoneypat I want to see the index column you created.
- PowerBI1234566 years agoPost Partisan
mahoneypat Hi - sorry for the delayed response, but is your code taking into the account the operation? For example, I want to look at deleted.