Forum Discussion
Group data rows by 'count distinct' value
- 9 years ago
In DAX you could create the following Table
New Table = SUMMARIZECOLUMNS('Table1'[Name],"Types",DISTINCTCOUNT('Table1'[Type]))Then create a measure on that new table
Measure = COUNTROWS('New Table')Then if you add the items to a grid you can display your end result
Somehow you need to do something in your dataset.
My suggestion would be to add a table with the aggregations, but it seems that's not a prefered solution so I created a solution in M (Edit Queries) as you can see in this video, illustrating the results from each step of the following code (the video starts at "PreviousStep" which was the result of loading the table from an Excel workbook):
let
Source = Excel.Workbook(File.Contents("C:\Users\Marcel\Documents\Forum bijdragen\Power BI Community\Group data rows by count distinct value.xlsx"), null, true),
Table3_Table = Source{[Item="Table3",Kind="Table"]}[Data],
PreviousStep = Table.TransformColumnTypes(Table3_Table,{{"Name", type text}, {"Type", type text}}),
AddedNoOfActivities = Table.AddColumn(PreviousStep, "No. Of Activities", (CurrentRecord) => List.Count(List.Distinct(Table.SelectRows(PreviousStep, each _[Name] = CurrentRecord[Name])[Type]))),
AddedNoOfNames = Table.AddColumn(AddedNoOfActivities, "No. Of Names", (CurrentRecord) => List.Count(List.Select(AddedNoOfActivities[Name], each _ = CurrentRecord[Name]))),
AddedCount = Table.AddColumn(AddedNoOfNames, "Count", each 1 / [No. Of Names]),
RemovedNoOfNames = Table.RemoveColumns(AddedCount,{"No. Of Names"}),
AddedNoActivities = Table.AddColumn(RemovedNoOfNames, "No. Activities", each {"One","Two","Three","Four"}{[No. Of Activities]-1}),
Typed = Table.TransformColumnTypes(AddedNoActivities,{{"No. Of Activities", Int64.Type}, {"Count", type number}, {"No. Activities", type text}})
in
Typed
In DAX you could create the following Table
New Table = SUMMARIZECOLUMNS('Table1'[Name],"Types",DISTINCTCOUNT('Table1'[Type]))Then create a measure on that new table
Measure = COUNTROWS('New Table')Then if you add the items to a grid you can display your end result
- aoifoc9 years agoFrequent Visitor
Thank you for the help on this!
I ended up creating the calculated table suggested by Phil_Seamark (a solution also partially suggested by MarcelBeug) and this did the job - I have the results I need now in a matrix in my report.
Thank you all.