cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SianM Frequent Visitor
Frequent Visitor

Multiple Sorting and Calculating from previous row

Hi All,

 

I am trying to track the occurance of a particular status in my data set over time (per unique ID). 

 

I have been reading a few pages and am worried it is not possible to do what I am trying without query editor. 

 

I am trying to generate a calculated column based on the previous row of my data, but this also requires a custom sort using two level column sort (apparently not possible).

Is there another way I can do this. This is how I build it in excel..... 

1. Sort by;
    a. ID - to group the leases together

    b. Report date - to get their status over time (number of reports)

 

2. Use countif and anested IF statement to check

    a. For the same property,
    b. has the status changed,

    c. if yes, has it changed to 'close out' (the status I am trying to count)

    d. if yes, count as 1. 

 

The results are below, in this snapshot, there are two properties, both that have progressed to closeout over the reporting period. 

 

When I apply this to my data set I can see how many properties closedout over the period. 

 

Is there a way I can do both of these steps in power BI? 

 

calc.JPG


Your help, ideas, suggestions would be greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User
Super User

Re: Multiple Sorting and Calculating from previous row

This video I made may help you https://youtu.be/xN2IRXQ2CvI



* Matt is a Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
3 REPLIES 3
Highlighted
Super User
Super User

Re: Multiple Sorting and Calculating from previous row

This video I made may help you https://youtu.be/xN2IRXQ2CvI



* Matt is a Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
Community Support Team
Community Support Team

Re: Multiple Sorting and Calculating from previous row

Hi SianM,

 

Based on my analysis, in DAX, you can create a calculate column and use formula like this pattern:

Count Closeout =
IF (
    CALCULATE (
        COUNTROWS ( Table[Milestones Status] ),
        FILTER (
            Table,
            Table[Lease ID] = EARLIER ( Table[Lease ID] )
                && Table[Milestones Status] <> EARLIER ( Table[Milestones Status] )
        )
    )
        <> 0,
    1,
    0
)

Regards,

Jimmy Tao

SianM Frequent Visitor
Frequent Visitor

Re: Multiple Sorting and Calculating from previous row

Hi @MattAllington,

 

Thank you for your help, this ended up working a treat!