Forum Discussion

Cogidubnus_Rex's avatar
Cogidubnus_Rex
Frequent Visitor
6 years ago
Solved

Sort by two columns in DAX

I've spent hours with one of my Power BI consultants trying to do in DAX what is a two-second operation in Query Editor, but unfortunately this isn't quite happening!   All we want to do is to sort...
  • v-juanli-msft's avatar
    6 years ago

    Hi Cogidubnus_Rex 

    In Edit queries,

    Add conditional column

    sort the "status rank" column first, then sort the "value" column, add an index column,

    Close &&apply, create columns

     

    clc invoice = CALCULATE(SUM('Table'[Invoice]),FILTER('Table','Table'[Index]<=EARLIER('Table'[Index])))
    
    on time = IF([Due status]="Past due",0,1)
    
    clc on time invo = IF([on time]=0,0,CALCULATE(SUM('Table'[Invoice]),FILTER('Table','Table'[Index]<=EARLIER('Table'[Index])&&[on time]=1)))
    
    clc on time% = [clc on time invo]/[clc invoice]

     

    Best Regards
    Maggie
    Community Support Team _ Maggie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.