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

Helper I

## Create a table containing the unique values of a user-sliced subset

I'm new in DAX and PowerBI, just run into a "simple" problem, hope someone give me a hint.

The problem is like this:  we have a data table behind a PowerBI report, its column "A" is of interest, and the report has several slicers work on that table.

The target is:

1. Firstly, to create an one-column dynamic table that contains the unique values of the sliced subset of the column "A" of the data table.  After each time user makes his selection on the slicers,  the table is automatically updated to refelct the new subsetting of the column "A".

2. secondly, to add a column to this dynamic table that contains the sequential numbers of the rows, i.e. 1, 2,..., N, with N the total number of rows.

Thank you!

Cheetah

1 ACCEPTED SOLUTION
Super User

@Cheetah
Indeed it is generating a number. Which you need to place it along with the desired column in one table visual. Please download the attached file and see how it works.

9 REPLIES 9
Super User

Hi @Cheetah
Attached sample file considering the brand column as an example. It should work on any column and any set of slicers.

You need to place the column in a table visual along with the following measure

``````No. =
RANKX (
CALCULATETABLE ( VALUES ( 'Product'[Brand] ), ALLSELECTED ( ) ),
CALCULATE ( MAX ( 'Product'[Brand] ) ),,
ASC,
Dense
)``````

Helper I

Hi @tamerj1 , thank you for the reply. Your images looks the very thing I want, but
the code is generating a number rather than a table, maybe you missed to post another section of code?
Cheetah

Super User

@Cheetah
Indeed it is generating a number. Which you need to place it along with the desired column in one table visual. Please download the attached file and see how it works.

Helper I

Thank you @tamerj1 ! great solution.

Community Support

Hi @Cheetah ,

In order to better understand your demands and give the right solution, could you please provide some more specific information? such as your desensitized example data and a screenshot of your desired results?

Thanks for your efforts & time in advance.

Best regards,
Community Support Team_ Binbin Yu

Helper I

Hi @v-binbinyu-msft , thank you for the advice, and sorry for the missing informations.  I got the problem solved. Thank you all as a great Community Support Team!

Super User

@Cheetah Not sure I 100% understand, but try this:

``````Measure =
VAR __Values = DISTINCT('Table'[A]) // whatever the user selects for A column, unique values
VAR __Text = CONCATENATEX(__Values,[A],"|")
VAR __Count = COUNTROWS(__Values)
VAR __Table =
ADDCOLUMNS(
GENERATESERIES(1,__Count,1),
"A",PATHITEM(__Text,[Value])
)
// do something with this dynamic table. You now have a dynamic indexed table where the index is the [Value] column and your A values are in the A column.
``````

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Helper I

HI @Greg_Deckler , thank you for the reply. I tried the code, it gives this error message:  "The syntax for ')' is incorrect."
Should I add a "return" line to the end of the code?

Super User

@Cheetah Yeah, I have no idea what you want to do with that table VAR so that is just a code snippet, not a complete measure.

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

## Helpful resources

Announcements

#### Power BI Monthly Update - July 2024

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

#### Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors
Top Kudoed Authors