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
Cheetah
Helper I
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

@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.

View solution in original post

9 REPLIES 9
tamerj1
Super User
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
)

1.png2.png

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

@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.

Thank you @tamerj1 ! great solution.

Anonymous
Not applicable

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

 

Hi @Anonymous , 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!  

Greg_Deckler
Super User
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.
    


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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?

@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.



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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.