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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.