Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

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!

  • 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:
    Hope this helps.

2 Replies

  • rajulshah's avatar
    rajulshah
    Resident Rockstar

    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:
    Hope this helps.

    • Anonymous's avatar
      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).