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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
ishanjain
Frequent Visitor

Rankx & earlier

I'm trying to build a calculated column called days_counter using rankx to find out how long the column tcc_sum was negative (in order of snapshot timestamp).

ishanjain_0-1670363429399.png

To my knowledge, I'm using the correct DAX but it does not reset when it sees "Neg" on 12/5 (the days counter should be 1 instead of 3 in the last row). This is the formula I'm using, pls help me.

 
 
Days_counter = RANKX (
    FILTER (
        'Capacity Change Hist',
        EARLIER ( 'Capacity Change Hist'[SERVICE_AREA] ) = 'Capacity Change Hist'[SERVICE_AREA]
        && EARLIER('Capacity Change Hist'[defc_neg_pos_]) = 'Capacity Change Hist'[defc_neg_pos_]
   
           
    ),
    'Capacity Change Hist'[Snapshot Timestamp],
    ,
    ASC
    ,Dense)

 

1 ACCEPTED SOLUTION
v-yadongf-msft
Community Support
Community Support

Hi @ishanjain ,

 

Add an index column in Power Query or in your data source.

vyadongfmsft_0-1670402088546.png

 

Create two columns:

Appear continuously = CALCULATE(MAX('Table'[Index])+1,ALL('Table'),'Table'[defc_neg_pos_] <> EARLIER('Table'[defc_neg_pos_]),'Table'[Index] <= EARLIER('Table'[Index]))

Rank = RANKX(FILTER('Table','Table'[SERVICE_AREA] = EARLIER('Table'[SERVICE_AREA]) && 'Table'[Appear continuously] = EARLIER('Table'[Appear continuously])),'Table'[Snapshot Timestamp],,ASC,Dense)

 

I think this is the result you want:

vyadongfmsft_1-1670402184266.png

 

Best regards,

Yadong Fang

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

View solution in original post

2 REPLIES 2
v-yadongf-msft
Community Support
Community Support

Hi @ishanjain ,

 

Add an index column in Power Query or in your data source.

vyadongfmsft_0-1670402088546.png

 

Create two columns:

Appear continuously = CALCULATE(MAX('Table'[Index])+1,ALL('Table'),'Table'[defc_neg_pos_] <> EARLIER('Table'[defc_neg_pos_]),'Table'[Index] <= EARLIER('Table'[Index]))

Rank = RANKX(FILTER('Table','Table'[SERVICE_AREA] = EARLIER('Table'[SERVICE_AREA]) && 'Table'[Appear continuously] = EARLIER('Table'[Appear continuously])),'Table'[Snapshot Timestamp],,ASC,Dense)

 

I think this is the result you want:

vyadongfmsft_1-1670402184266.png

 

Best regards,

Yadong Fang

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

@v-yadongf-msft I figured it out! I had to change ALL(table) to ALLEXCEPT(Table[service area]) in "Appear continously because my table had a lot of areas and it was not working dynamically for one single area and that worked. Thanks a ton, you saved me 🙂

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.