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
freidav1984
Frequent Visitor

DAX measure which returns an index (counter) in a table depending on the displayed table items

Hi All!

 

I have a challenge, I would like to display a counter value in table visual, which should return an increasing number (increment +1) depending on the displayed and filtered items shown in the table visual.

 

I have a calculated table, which contains invoices' data.

 

IDPartnerCategory - MainCategory - Sub
AX1AAA
AV6BAB
ZT1CAC
DS2DBA
AS7DBB

 

If I put all data fields from the above shown table into a table visualization, I would like to add a measure which returns an index or counter value based on how the table is filtered. What I want to achieve.

 

Example 1.:

If I filter the table for category - main = 'A' then I would need the following result in the table visualization

IDPartnerCategory - MainCategory - SubMEASURE - Index
AX1AAA1
AV6BAB2
ZT1CAC3

 

Example 2.:

If I filter the table for category - main = 'B' then I would need the following result in the table visualization

 

IDPartnerCategory - MainCategory - SubMEASURE - Index
DS2DBA1
AS7DBB2

 

Do you have any solution on this issue?

Thanks a lot!

 

David

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @freidav1984 ,

 

I suggest you to try this code to create a measure.

Dynamic Index = 
VAR _1 =
    ADDCOLUMNS (
        ALLSELECTED ( 'Table' ),
        "Merage", COMBINEVALUES ( " ", [Category - Main], [Category - Sub] )
    )
VAR _2 =
    ADDCOLUMNS ( _1, "Index", RANKX ( _1, [Merage],, ASC, DENSE ) )
RETURN
    SUMX ( FILTER ( _2, [ID] = MAX ( 'Table'[ID] ) ), [Index] )

Result is as below.

vrzhoumsft_0-1686293446030.png

vrzhoumsft_1-1686293457125.png

 

Best Regards,
Rico Zhou

 

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-rzhou-msft
Community Support
Community Support

Hi @freidav1984 ,

 

I suggest you to try this code to create a measure.

Dynamic Index = 
VAR _1 =
    ADDCOLUMNS (
        ALLSELECTED ( 'Table' ),
        "Merage", COMBINEVALUES ( " ", [Category - Main], [Category - Sub] )
    )
VAR _2 =
    ADDCOLUMNS ( _1, "Index", RANKX ( _1, [Merage],, ASC, DENSE ) )
RETURN
    SUMX ( FILTER ( _2, [ID] = MAX ( 'Table'[ID] ) ), [Index] )

Result is as below.

vrzhoumsft_0-1686293446030.png

vrzhoumsft_1-1686293457125.png

 

Best Regards,
Rico Zhou

 

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.

Top Solution Authors