Forum Discussion

CBXS's avatar
CBXS
Frequent Visitor
3 years ago
Solved

Calculated column based on multiple conditions using DAX

Hello. I could use some assistance regarding a DAX algorithm, since I'm inexperienced in algorithms of this complexity. I have about 15k rows with data similar to the table shown below.   I wish ...
  • v-zhangti's avatar
    v-zhangti
    3 years ago

    Hi, CBXS 

     

    First, you need to add an index column to Power Query.

     

    Column = 
    Var _N1=CALCULATE(COUNT('Table'[Index]),ALLEXCEPT('Table','Table'[Person],'Table'[Classification],'Table'[Weeknumber],'Table'[Day_in_week]))
    Var _N2=CALCULATE(MIN('Table'[Index]),ALLEXCEPT('Table','Table'[Person],'Table'[Classification],'Table'[Weeknumber],'Table'[Day_in_week]))
    Var _N3=CALCULATE(COUNT('Table'[Index]),ALLEXCEPT('Table','Table'[Person],'Table'[Weeknumber],'Table'[Day_in_week]))
    Var _Rank=RANKX(FILTER('Table',[Person]=EARLIER('Table'[Person])&&[Weeknumber]=EARLIER('Table'[Weeknumber])),[Day_in_week],,ASC)
    Return
    IF(_N1>1&&[Index]=_N2,1,IF(_N3>1&&[Classification]="A",1,IF(_Rank<=2&&_N3=1,1,BLANK())))
    One week more A = 
     Var _RankA=IF([Classification]="A",RANKX(FILTER('Table',[Person]=EARLIER('Table'[Person])&&[Weeknumber]=EARLIER('Table'[Weeknumber])&&[Classification]="A"),[Day_in_week],,ASC),BLANK())
    Return
    IF(_RankA<=2&&_RankA<>BLANK()&&[Column]=BLANK(),1,BLANK())
    Decision = SWITCH(TRUE(),
    [Column]=1,1,
    [One week more A]=1,1,
    0)

     

    Is this the result you expect?

     

    Best Regards,

    Community Support Team _Charlotte

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.