Forum Discussion
Find & count certain values for each column
Dataframe 1Dataframe 2
Df1 contains rows with info about systems. Df2 contains rows that in essence are counts of the columns from Df1.
Regards
ok, so you want to count rows in Dataframe1, that meet certain criteria
in DAX this can be achieved like this
AssetType_Empty= CALCULATE(COUNTROWS(DF1),DF1[AssetType] = BLANK()) AssetType_Unknown= CALCULATE(COUNTROWS(DF1),DF1[AssetType] = "Unknown")
assuming Dataframe2 is supposed to only serve as a source for the dropdown in the yellow visual, the following syntax would work
Empty =
VAR ColumnName = SELECTEDVALUE(DF2[key])
RETURN
SWITCH(ColumnName,
"AssetType",[AssetType_Empty],
"Other column",[Other column_Empty],
BLANK()
)then very similiar measure for Unknown
Is this what you were looking for, or do you look for a way to modify values in DF2?
- jk918 years agoFrequent Visitor
Hi Stachu,
Thanks for your help. Using your solution, I'd have to manually create two measures (x_empty & x_unknown) for each column x I guess? And for an overall accuracy / integrity measure i'd have to combine those measures into a single score. That could work although it would be quite a hassle with 35 rows hehe.
Kind regards
- Stachu8 years agoCommunity Champion
you could create just 2 measures, and include the column specific ones as variables
Empty = VAR ColumnName = SELECTEDVALUE(DF2[key]) VAR AssetType_Empty = CALCULATE(COUNTROWS(DF1),DF1[AssetType] = BLANK()) VAR Other_column_Empty = CALCULATE(COUNTROWS(DF1),DF1[Other_column] = BLANK()) RETURN SWITCH(ColumnName, "AssetType",AssetType_Empty, "Other column",Other_column_Empty, BLANK() )if you could unpivot the columns so they would all be in 2 columns like ColumnName & ColumnValue then it's just 2 very simple measures. This approach requires some drastic changes to your data model
- jk918 years agoFrequent Visitor
Thanks again, I am not sure whether I have made myself as clear as I would like so I'll try to rephrase. What I need is a score for data quality for both the whole dataframe(df1) and every single column in there. My R code simply counts the occurence of empty or unknown per column and saves those two counts in a second dataframe. However, the two df's have different structures and therefore they do not support cross-filtering.
What I'd like to have is that I can select a column (e.g. AssetType) using a slicer and that when I apply a filter (e.g. AVClient = "McAfee") the metrics update and only shows the unknown and empty counts for each row where AVClient equals McAfee.
However, if I deselect the AssetType column, it should show a score for the whole dataframe where AVClient = McAfee. I guess this requires looping over every cell in the df or calculating two scores for each column beforehand.