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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
talkprem
Helper I
Helper I

Unique ids from a string using DAX measure

Hi All,

 

I have data in this manner

idvalue
10023123,456
10023123,456,789
10023456,789

which by using a DAX measure i need to show in tablix visual as below for the value column, please dont give reply for power query as that may not fit my purpose.
Looking for DAX measure approach

idvalue
10023123,456,789
2 ACCEPTED SOLUTIONS

@talkprem Updated verison, i have modified it to sort based on ASC/DESC you can control that as you by changing the parameter inside CONCATENATEX.

 

Unique ID String = 
IF ( 
    ISINSCOPE ( report_table[site_id] ),
    VAR NumberCount =
        ADDCOLUMNS (
            SUMMARIZE ( report_table, report_table[site_id], report_table[value] ),
            "@Number Count",
                LEN ( report_table[value] ) - LEN ( SUBSTITUTE ( report_table[value], ",", "" ) ) + 1
        )
    VAR MaxNumberCount =
        MAXX ( NumberCount, [@Number Count] )
    VAR GenerateNumberSeries = 
        SELECTCOLUMNS ( 
            GENERATESERIES ( 1, MaxNumberCount, 1 ), 
            "@Int", [value] 
        )
    VAR TempTable =
        FILTER (
            GENERATE ( NumberCount, GenerateNumberSeries ),
            [@Int] <= [@Number Count]
        )
    VAR SplitTextByNumber =
        ADDCOLUMNS (
            TempTable,
            "@Final String", INT ( TRIM ( PATHITEM ( SUBSTITUTE ( report_table[value], ",", "|" ), [@Int], TEXT ) ) )
        )
    VAR DistinctNumbers = 
        DISTINCT ( 
            SELECTCOLUMNS ( 
                SplitTextByNumber,
                [@Final String]
            )
        )
    VAR Result = 
        CONCATENATEX ( 
            DistinctNumbers,
            [@Final String],
            ", ",
            [@Final String], DESC
        )
    RETURN 
        Result
)

 

 

View solution in original post

talkprem
Helper I
Helper I

After some debugging the DAX code, I found that

MaxNumberCount
variable is not working and the code fails to work.

after looking at my data i found that max number of comma separate values in a single row are 5. So I hard coded the number 10 and code is working as per expectations. Till 10 iterations. Many thanks and Shoutout to @AntrikshSharma for helping out.

Final code which is working fine for me (this can work even with null values in value column) -

 

 

 

 

Unique ID String null ok = 
IF ( 
    ISINSCOPE ( report_table[site_id] ),
    VAR NumberCount =
        ADDCOLUMNS (
            SUMMARIZE ( report_table, report_table[site_id], report_table[value] ),
            "@Number Count",
                LEN ( report_table[value] ) - LEN ( SUBSTITUTE ( report_table[value], ",", "" ) ) + 1
        )
  --  VAR MaxNumberCount =
  --      MAXX ( NumberCount, [@Number Count] )
    VAR GenerateNumberSeries = 
        SELECTCOLUMNS ( 
            GENERATESERIES ( 1, 10, 1 ), 
            "@Int", [value] 
        )
    VAR TempTable =
        FILTER (
            GENERATE ( NumberCount, GenerateNumberSeries ),
            [@Int] <= [@Number Count]
        )
    VAR SplitTextByNumber =
        ADDCOLUMNS (
            TempTable,
            "@Final String", INT ( TRIM ( PATHITEM ( SUBSTITUTE ( report_table[value], ",", "|" ), [@Int], TEXT ) ) )
        )
    VAR DistinctNumbers = 
        DISTINCT ( 
            SELECTCOLUMNS ( 
                SplitTextByNumber,
                [@Final String]
            )
        )
    VAR Result = 
        CONCATENATEX ( 
            DistinctNumbers,
            [@Final String],
            ", ",
            [@Final String], DESC
        )
    RETURN 
        Result
)

 

 

View solution in original post

9 REPLIES 9
talkprem
Helper I
Helper I

After some debugging the DAX code, I found that

MaxNumberCount
variable is not working and the code fails to work.

after looking at my data i found that max number of comma separate values in a single row are 5. So I hard coded the number 10 and code is working as per expectations. Till 10 iterations. Many thanks and Shoutout to @AntrikshSharma for helping out.

Final code which is working fine for me (this can work even with null values in value column) -

 

 

 

 

Unique ID String null ok = 
IF ( 
    ISINSCOPE ( report_table[site_id] ),
    VAR NumberCount =
        ADDCOLUMNS (
            SUMMARIZE ( report_table, report_table[site_id], report_table[value] ),
            "@Number Count",
                LEN ( report_table[value] ) - LEN ( SUBSTITUTE ( report_table[value], ",", "" ) ) + 1
        )
  --  VAR MaxNumberCount =
  --      MAXX ( NumberCount, [@Number Count] )
    VAR GenerateNumberSeries = 
        SELECTCOLUMNS ( 
            GENERATESERIES ( 1, 10, 1 ), 
            "@Int", [value] 
        )
    VAR TempTable =
        FILTER (
            GENERATE ( NumberCount, GenerateNumberSeries ),
            [@Int] <= [@Number Count]
        )
    VAR SplitTextByNumber =
        ADDCOLUMNS (
            TempTable,
            "@Final String", INT ( TRIM ( PATHITEM ( SUBSTITUTE ( report_table[value], ",", "|" ), [@Int], TEXT ) ) )
        )
    VAR DistinctNumbers = 
        DISTINCT ( 
            SELECTCOLUMNS ( 
                SplitTextByNumber,
                [@Final String]
            )
        )
    VAR Result = 
        CONCATENATEX ( 
            DistinctNumbers,
            [@Final String],
            ", ",
            [@Final String], DESC
        )
    RETURN 
        Result
)

 

 

AntrikshSharma
Super User
Super User

@talkprem 

AntrikshSharma_1-1718711723932.png

 

Unique ID String = 
IF ( 
    ISINSCOPE ( t[id] ),
    VAR NumberCount =
        ADDCOLUMNS (
            t,
            "@Number Count",
                LEN ( t[value] ) - LEN ( SUBSTITUTE ( t[value], ",", "" ) ) + 1
        )
    VAR MaxNumberCount =
        MAXX ( NumberCount, [@Number Count] )
    VAR GenerateNumberSeries = 
        SELECTCOLUMNS ( 
            GENERATESERIES ( 1, MaxNumberCount, 1 ), 
            "@Int", [value] 
        )
    VAR TempTable =
        FILTER (
            GENERATE ( NumberCount, GenerateNumberSeries ),
            [@Int] <= [@Number Count]
        )
    VAR SplitTextByNumber =
        ADDCOLUMNS (
            TempTable,
            "@Final String", TRIM ( PATHITEM ( SUBSTITUTE ( t[value], ",", "|" ), [@Int], TEXT ) )
        )
    VAR DistinctNumbers = 
        DISTINCT ( 
            SELECTCOLUMNS ( 
                SplitTextByNumber,
                [@Final String]
            )
        )
    VAR Result = 
        CONCATENATEX ( 
            DistinctNumbers,
            [@Final String],
            ", "
        )
    RETURN 
        Result
)

 

 

Hi AntrikshSharma,

 

I have tried the dax query you posted but i got an error,
"the arguments of a generateseries function cant be blank"
i have 5 column like this

plate   datetime   material   site_id   value  
123 6/17/2024 345 10023 123,456,789
123 6/17/2024 345 10023 123,456
123 6/17/2024 345 10023 456,789

 to this 

plate   datetime  material  site_id  value  
123 6/17/2024 345 10023 123,456,789

can you have a look in the dax query once please table name "report_table"



@talkprem Updated verison, i have modified it to sort based on ASC/DESC you can control that as you by changing the parameter inside CONCATENATEX.

 

Unique ID String = 
IF ( 
    ISINSCOPE ( report_table[site_id] ),
    VAR NumberCount =
        ADDCOLUMNS (
            SUMMARIZE ( report_table, report_table[site_id], report_table[value] ),
            "@Number Count",
                LEN ( report_table[value] ) - LEN ( SUBSTITUTE ( report_table[value], ",", "" ) ) + 1
        )
    VAR MaxNumberCount =
        MAXX ( NumberCount, [@Number Count] )
    VAR GenerateNumberSeries = 
        SELECTCOLUMNS ( 
            GENERATESERIES ( 1, MaxNumberCount, 1 ), 
            "@Int", [value] 
        )
    VAR TempTable =
        FILTER (
            GENERATE ( NumberCount, GenerateNumberSeries ),
            [@Int] <= [@Number Count]
        )
    VAR SplitTextByNumber =
        ADDCOLUMNS (
            TempTable,
            "@Final String", INT ( TRIM ( PATHITEM ( SUBSTITUTE ( report_table[value], ",", "|" ), [@Int], TEXT ) ) )
        )
    VAR DistinctNumbers = 
        DISTINCT ( 
            SELECTCOLUMNS ( 
                SplitTextByNumber,
                [@Final String]
            )
        )
    VAR Result = 
        CONCATENATEX ( 
            DistinctNumbers,
            [@Final String],
            ", ",
            [@Final String], DESC
        )
    RETURN 
        Result
)

 

 

@AntrikshSharma We have

values like " " and NULLS which are causing leading or trailing "," (commas to be added) in the output. 
could you please help me in this brother?


current output 

idvalue
10023,123,456,789,
10023123,456,789,

 

expected output

idvalue
10023123,456,789
10024123,456,789

thanks in advance.

Hi,

 

Thanks for replying but again i am getting the same error
"the arguments of a generateseries function cant be blank"
Unable to understand why this error is coming.
Respect to you brother for helping out.

@talkprem Download the file from here and then you can try to replicate in your model: https://drive.google.com/file/d/1pf84uc6YM_zTGuI5IDOOjhFnrY49AMe_/view?usp=sharing

In my data there are few rows which have NULL data in the value column. Due to this i am getting an error. Could you please add a row in your data having null in value column and check once?
once i added the null value record for the same id it got the same error.

Hi Antrishk,

 

Thank you for helping out i tried to use the measure but got an error , "the arguments of generate series function cant be blank". i actually have few more columns which i need to show in this manner.

id number date id material value
D77656/17/2024 10023 4002123,456
D77656/17/2024 10023 4002123,456,789
D77656/17/2024 10023 4002456,789

 

to something like this

 

id number date idmaterial value
D7765 6/17/2024 10023 4002123,456,789

 

can you please help me, many many thanks and respect in advance.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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