Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
SianM
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
MattAllington
Community Champion
Community Champion

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



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

View solution in original post

3 REPLIES 3
v-yuta-msft
Community Support
Community Support

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

MattAllington
Community Champion
Community Champion

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



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Hi @MattAllington,

 

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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.