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

Check for values in group

Hi,

 

I have a datatable similar to the following:

CategoryIDdategoodbadundecided
Cat111AAsome_date100
Cat111AAsome_date100
Cat122BBsome_date100
Cat122BBsome_date100
Cat122BBsome_date010
Cat233CCsome_date100
Cat233CCsome_date010
Cat233CCsome_date001
Cat244DDsome_date100
Cat244DDsome_datenullnullnull

The rules are:

  • There is always just one value in columns "good", "bad" and "undecided" for each row.
  • There may be rows with null values in all of those columns, assume then it's "good".

What I need are measures:

  • Measure 1: If all values for certain ID are "good" return 1, else return 0.
  • Measure 2: If there is any "bad" value check, if there is any "undecided" value and choose last one by date.
  • Measure 3: If there is any "undecided value check, if there is any "bad" value and choose last one by date.
    So if there is one bad and one undecided the result value for this ID should be the last one.

So the result visual matrix should look like this:

CategoryIDMeasure 1 [good]Measure 2 [bad]Measure 3 [undecided]
Cat1 110
 11AA100
 22BB010
Cat2 101
 33CC001
 44DD100


I can't figure it out, I tried with SUMMARIZECOLUMNS and GROUPBY functions but in each approach the problem was I couldnt summarize the result table.

Thank you in advance!

1 ACCEPTED SOLUTION
rajulshah
Super User
Super User

Hello @Anonymous,

Please create following measures:

Good Rating = 
VAR SelectedID = SELECTEDVALUE(Rating[ID])
VAR TotalValues = CALCULATE(COUNT(Rating[ID]),FILTER(ALL(Rating),Rating[ID]=SELECTEDVALUE(Rating[ID])))
VAR GoodRatingCount = CALCULATE(COUNT(Rating[ID]),FILTER(Rating,Rating[good]=1 || ISBLANK(Rating[good])))
VAR GoodRating = IF(TotalValues=GoodRatingCount,1,0)
VAR CategoryRatingTable = FILTER(SUMMARIZE(Rating,Rating[Category],Rating[ID],"GoodRating",CALCULATE(COUNT(Rating[ID]),FILTER(Rating,Rating[good]=1 || ISBLANK(Rating[good]))),"TotalValues",CALCULATE(COUNT(Rating[ID]),ALLEXCEPT(Rating,Rating[ID]))),[GoodRating]=[TotalValues])
RETURN IF(ISBLANK(SelectedID),COUNTX(CategoryRatingTable,Rating[ID]),GoodRating)
Bad Rating = 
VAR TotalValues = CALCULATE(COUNT(Rating[ID]),FILTER(ALL(Rating),Rating[ID]=SELECTEDVALUE(Rating[ID])))
VAR BadRating = CALCULATE(COUNT(Rating[ID]),FILTER(Rating,Rating[bad]=1 || ISBLANK(Rating[bad])))
VAR Undecided = CALCULATE(COUNT(Rating[ID]),FILTER(Rating,Rating[undecided]=1 || ISBLANK(Rating[undecided])))
RETURN IF(BadRating>=1 && Undecided=0,1,0)
Undecided Rating = 
VAR TotalValues = CALCULATE(COUNT(Rating[ID]),FILTER(ALL(Rating),Rating[ID]=SELECTEDVALUE(Rating[ID])))
VAR Undecided = CALCULATE(COUNT(Rating[ID]),FILTER(Rating,Rating[undecided]=1 || ISBLANK(Rating[undecided])))
RETURN IF([Good Rating]=0 && [Bad Rating]=0 && Undecided>0,1,0)

 

The result is as follows:
Rating.pngHope this helps.

View solution in original post

2 REPLIES 2
rajulshah
Super User
Super User

Hello @Anonymous,

Please create following measures:

Good Rating = 
VAR SelectedID = SELECTEDVALUE(Rating[ID])
VAR TotalValues = CALCULATE(COUNT(Rating[ID]),FILTER(ALL(Rating),Rating[ID]=SELECTEDVALUE(Rating[ID])))
VAR GoodRatingCount = CALCULATE(COUNT(Rating[ID]),FILTER(Rating,Rating[good]=1 || ISBLANK(Rating[good])))
VAR GoodRating = IF(TotalValues=GoodRatingCount,1,0)
VAR CategoryRatingTable = FILTER(SUMMARIZE(Rating,Rating[Category],Rating[ID],"GoodRating",CALCULATE(COUNT(Rating[ID]),FILTER(Rating,Rating[good]=1 || ISBLANK(Rating[good]))),"TotalValues",CALCULATE(COUNT(Rating[ID]),ALLEXCEPT(Rating,Rating[ID]))),[GoodRating]=[TotalValues])
RETURN IF(ISBLANK(SelectedID),COUNTX(CategoryRatingTable,Rating[ID]),GoodRating)
Bad Rating = 
VAR TotalValues = CALCULATE(COUNT(Rating[ID]),FILTER(ALL(Rating),Rating[ID]=SELECTEDVALUE(Rating[ID])))
VAR BadRating = CALCULATE(COUNT(Rating[ID]),FILTER(Rating,Rating[bad]=1 || ISBLANK(Rating[bad])))
VAR Undecided = CALCULATE(COUNT(Rating[ID]),FILTER(Rating,Rating[undecided]=1 || ISBLANK(Rating[undecided])))
RETURN IF(BadRating>=1 && Undecided=0,1,0)
Undecided Rating = 
VAR TotalValues = CALCULATE(COUNT(Rating[ID]),FILTER(ALL(Rating),Rating[ID]=SELECTEDVALUE(Rating[ID])))
VAR Undecided = CALCULATE(COUNT(Rating[ID]),FILTER(Rating,Rating[undecided]=1 || ISBLANK(Rating[undecided])))
RETURN IF([Good Rating]=0 && [Bad Rating]=0 && Undecided>0,1,0)

 

The result is as follows:
Rating.pngHope this helps.

Anonymous
Not applicable

Thank you, @rajulshah!

 

It took me some time to adjust your solution to my real data (I had to add lot's of additional filtering there) but the first measure works as I need it to work and thus I'm accepting your idea as the solution to my problem. I'll work with other two measures now but these probably won't be as problematic as the first one (less customization).

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.