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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Index depending on date, category and first case

Hi everybody,

 

I'm still new in this and need help to index or rank my table.

 

Here is the situation, I have a table with a date, country, and cases. I want to index/rank by date by country but starting to count by the first appearance.

 

Below is an example of my data, the Index Column is the desired result, right now I do not have that column. Take US and Mexico as an example, the first case (Case column diff than 0) is on March 13th, so I want that to be the index/rank 1 and then the next day 2, next day 3, and so on but just for the US. Then Mexico the first case (case column diff than 0) is on March 19th, so I want that to be index/rank 1 for Mexico, next day 2, next day 3.

 

Any ideas, I found a formula using RANKX in combination with EARLIER, but that was fine, but it started counting since the first country appearance, no matter if the cases were 0, I want to start counting when it detects the first case.

 

 

DateCountryCasesIndex
Tuesday, March 10, 2020Mexico0 
Tuesday, March 10, 2020US0 
Wednesday, March 11, 2020Mexico0 
Wednesday, March 11, 2020US0 
Thursday, March 12, 2020Mexico0 
Thursday, March 12, 2020US0 
Friday, March 13, 2020Mexico0 
Friday, March 13, 2020US51
Saturday, March 14, 2020Mexico0 
Saturday, March 14, 2020US02
Sunday, March 15, 2020Mexico0 
Sunday, March 15, 2020US123
Monday, March 16, 2020Mexico0 
Monday, March 16, 2020US294
Tuesday, March 17, 2020Mexico0 
Tuesday, March 17, 2020US395
Wednesday, March 18, 2020Mexico0 
Wednesday, March 18, 2020US466
Thursday, March 19, 2020Mexico11
Thursday, March 19, 2020US787
Friday, March 20, 2020Mexico12
Friday, March 20, 2020US838
Saturday, March 21, 2020Mexico23
Saturday, March 21, 2020US1319
Sunday, March 22, 2020Mexico24
Sunday, March 22, 2020US13810
Monday, March 23, 2020Mexico35
Monday, March 23, 2020US19611
1 ACCEPTED SOLUTION
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

try this 

Column = 
VAR __filterCountry = ALLEXCEPT( 'Table', 'Table'[Country] )
VAR __firstDate =
    CALCULATE(
        MIN( 'Table'[Date] ),
        __filterCountry,
        'Table'[Cases] > 0
    )
VAR __tbl = 
    CALCULATETABLE(
        'Table',
        __filterCountry,
        'Table'[Date] >= __firstDate
    )
RETURN 
IF( 
    'Table'[Date] >= __firstDate, 
    RANKX(
        __tbl,
        'Table'[Date],,
        ASC,
        Dense
    )
)

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

View solution in original post

3 REPLIES 3
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

try this 

Column = 
VAR __filterCountry = ALLEXCEPT( 'Table', 'Table'[Country] )
VAR __firstDate =
    CALCULATE(
        MIN( 'Table'[Date] ),
        __filterCountry,
        'Table'[Cases] > 0
    )
VAR __tbl = 
    CALCULATETABLE(
        'Table',
        __filterCountry,
        'Table'[Date] >= __firstDate
    )
RETURN 
IF( 
    'Table'[Date] >= __firstDate, 
    RANKX(
        __tbl,
        'Table'[Date],,
        ASC,
        Dense
    )
)

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Anonymous
Not applicable

This did the trick, thank you! Definitely I have more to learn.

Hi @Anonymous 

 

No problem!

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.