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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.