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
SBC
Helper III
Helper III

Help Needed: Generating Sequential Serial Numbers in Power BI with Date Slicer

Hello ,

I'm working on a Power BI report and need assistance with generating sequential serial numbers. My data includes columns for "Name" and "Account" (in string format), and I use a date column as a slicer.

Objective:
I want to add a serial number to each name in the table visual. When filtering by date, the serial numbers should remain sequential (1, 2, 3, ...) without any gaps.

Challenge:
When users select a date using the slicer, I want the serial numbers to regenerate in sequence for the filtered names associated with that specific date. The goal is to ensure no gaps appear in the numbering.

Sample Data:

Name Account Date
John SmithACC123452024-10-01
Maria GarciaACC678902024-10-02
Li WeiACC543212024-10-01
Emily JohnsonACC334452024-10-01

Expected Output When Filtering by "2024-10-01":

Serial Number Name Account
1John SmithACC12345
2Li WeiACC54321
3Emily JohnsonACC33445

Has anyone implemented a similar solution or can suggest a DAX formula or method to achieve this? Any guidance would be greatly appreciated!Thank you in advance for your help! 

2 ACCEPTED SOLUTIONS

hI @SBC 

The logic is doing exactly the same here are some more scenarios I have added to the dataset

Rupak_bi_4-1729578075099.png

 

And here are the outputs

Rupak_bi_1-1729577838109.pngRupak_bi_2-1729577848131.pngRupak_bi_3-1729577863153.png

the logic is simply partitioning based on date. 



Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/

View solution in original post

v-xuxinyi-msft
Community Support
Community Support

Hi @SBC 


Thanks for the reply from Rupak_bi . 

 

The following testing is for your reference.

 

Sample:

vxuxinyimsft_1-1729580576264.png

 

1. Add an index column in Power Query(Transform data)

vxuxinyimsft_2-1729580716713.png

 

2. Create a calculated table as the slicer

Date = VALUES('Table'[Date])

 

vxuxinyimsft_3-1729581025877.png

 

3. Create two measures as follow.

Index1 = MAX([Index])

 

Rank = 
VAR _selectedDate =
    SELECTEDVALUE ( 'Date'[Date] )
RETURN
    IF (
        _selectedDate = BLANK (),
        RANKX ( ALL ( 'Table' ), [Index1],, ASC, DENSE ),
        IF (
            MAX ( [Date] ) = _selectedDate,
            RANKX (
                FILTER ( ALL ( 'Table' ), [Date] = _selectedDate ),
                [Index1],
                ,
                ASC,
                DENSE
            ),
            BLANK ()
        )
    )

 

Output:

vxuxinyimsft_4-1729581201887.png

 

vxuxinyimsft_5-1729581217868.png

 

vxuxinyimsft_6-1729581261166.png

Best Regards,
Yulia Xu

 

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

6 REPLIES 6
v-xuxinyi-msft
Community Support
Community Support

Hi @SBC 


Thanks for the reply from Rupak_bi . 

 

The following testing is for your reference.

 

Sample:

vxuxinyimsft_1-1729580576264.png

 

1. Add an index column in Power Query(Transform data)

vxuxinyimsft_2-1729580716713.png

 

2. Create a calculated table as the slicer

Date = VALUES('Table'[Date])

 

vxuxinyimsft_3-1729581025877.png

 

3. Create two measures as follow.

Index1 = MAX([Index])

 

Rank = 
VAR _selectedDate =
    SELECTEDVALUE ( 'Date'[Date] )
RETURN
    IF (
        _selectedDate = BLANK (),
        RANKX ( ALL ( 'Table' ), [Index1],, ASC, DENSE ),
        IF (
            MAX ( [Date] ) = _selectedDate,
            RANKX (
                FILTER ( ALL ( 'Table' ), [Date] = _selectedDate ),
                [Index1],
                ,
                ASC,
                DENSE
            ),
            BLANK ()
        )
    )

 

Output:

vxuxinyimsft_4-1729581201887.png

 

vxuxinyimsft_5-1729581217868.png

 

vxuxinyimsft_6-1729581261166.png

Best Regards,
Yulia Xu

 

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

Rupak_bi
Post Prodigy
Post Prodigy

hi @SBC 

here is you solution

Rupak_bi_0-1729519466464.pngRupak_bi_1-1729519484750.png

measure:

rank = CALCULATE( RANK(all('Table'),FIRST,PARTITIONBY('Table'[Date])))


Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/

Thanks @Rupak_bi , for responding to my query. However, the solution isn't working as expected, as it is displaying incorrect serial numbers instead of the expected ones.

SBC_0-1729565987314.png

 

 

 

Hi @SBC 

Based on the sample data you shared, I hope it was working. If you could share sample data which represents your dataset( not actual values) , would be better to check the error. However normally rankx is being used to generate index if you have unique values in a column ( like date or numbers). But here it is alphabets to be sequenced. 



Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/

Hi @Rupak_bi ,

The logic we are aiming for is to display a serial number for each row in the table visual, starting from S.No: 1, 2, 3, and so on, regardless of the data or level present in the table.

Table Visual :

S.NONameAccountEvent
1AAaqwerFA
2BBqdwtyCA
3CCoutreBA
4FFtwerPA

hI @SBC 

The logic is doing exactly the same here are some more scenarios I have added to the dataset

Rupak_bi_4-1729578075099.png

 

And here are the outputs

Rupak_bi_1-1729577838109.pngRupak_bi_2-1729577848131.pngRupak_bi_3-1729577863153.png

the logic is simply partitioning based on date. 



Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/

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!

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.