Forum Discussion
Distinct Count with value in same table
- 7 years ago
Another thing you may want to try then is instead of appending the two data tables, merge them side by side.
So intead of your original table, you end up with something like this:
CODE PREV_STATE CUR_STATE CHANGED 1015 A A TRUE 1016 A B FALSE 1017 B B TRUE If whatever index you're using for each row stays the same between days, this may be a better way to store your data. Be sure to check my previous reply for DAX code to solve your original problem
Though I'm not sure why you want this as a PowerQuery function instead of as a DAX, but it's possible.
Go into the Query Editor, and at the far left of the Transform tab, you should see a Group By button. Go through that wizard and Group By both Code and State. Here's the entirety of the Power Query I used to create the results table as you have with the data snippet provided, with the bolded section being the important one:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwNFXSUXJUitUBc8yQOeZAjhOMY4rMMUPmYChzRuagmxYLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Code = _t, State = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", Int64.Type}, {"State", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Code", "State"}, {{"Result", each Table.RowCount(_), type number}})
in
#"Grouped Rows"You should be able to copy/paste the above into the advanced editor and play with it directly.
Cmcmahan, I did it, but I lost the another columns, I want to keep them (in the example bottom I didn´t show them).
PD: I suggested Power Query for better performance, (I think). If there is another way to achieve this without impacting performance, feel free to help me.