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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Conditionally Counting Rows and Assigning Number to Row

Hi all,

 

I have a list of payment attempts, and I'd like to add in the attempt number for each row. A "string" of attempts would be where the date is equal to or is the next day. When you get to a day where this is not the case, the counter needs to "reset". This would be for each ID. So there should be a reset per ID as well as the break in the date string.

 

For example, for the data below I would like the final data to look something like this, starting only with the first two columns:

image.png

 

Initially I created a "unique ID" by combining the month number and the ID, and grouped by this ID to get the count, but I'd like to be able to assign the attempt number to each date and this also didn't work for attempt strings that went over two months.

 

Just can't figure it out, any help would be welcome.

 

1 ACCEPTED SOLUTION
v-cherch-msft
Employee
Employee

Hi @Anonymous

 

You may add a index column first. Then you may get the rank with below dax.

Column =
IF (
    Table1[DateCreated]
        = LOOKUPVALUE ( Table1[DateCreated], Table1[Index], Table1[Index] - 1 )
        || Table1[DateCreated]
            = LOOKUPVALUE ( Table1[DateCreated], Table1[Index], Table1[Index] - 1 )
                + 1,
    0,
    1
)
Column 2 =
SUMX (
    FILTER ( Table1, Table1[Index] <= EARLIER ( Table1[Index] ) ),
    Table1[Column]
)
Rank =
RANKX (
    FILTER ( Table1, Table1[Column 2] = EARLIER ( Table1[Column 2] ) ),
    Table1[Index],
    ,
    ASC
)

1.png

 

Regards,

Cherie

Community Support Team _ Cherie Chen
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

1 REPLY 1
v-cherch-msft
Employee
Employee

Hi @Anonymous

 

You may add a index column first. Then you may get the rank with below dax.

Column =
IF (
    Table1[DateCreated]
        = LOOKUPVALUE ( Table1[DateCreated], Table1[Index], Table1[Index] - 1 )
        || Table1[DateCreated]
            = LOOKUPVALUE ( Table1[DateCreated], Table1[Index], Table1[Index] - 1 )
                + 1,
    0,
    1
)
Column 2 =
SUMX (
    FILTER ( Table1, Table1[Index] <= EARLIER ( Table1[Index] ) ),
    Table1[Column]
)
Rank =
RANKX (
    FILTER ( Table1, Table1[Column 2] = EARLIER ( Table1[Column 2] ) ),
    Table1[Index],
    ,
    ASC
)

1.png

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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