Forum Discussion
Unique ids from a string using DAX measure
- 2 years ago
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 ) - 2 years ago
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 )
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
- talkprem2 years ago
Helper I
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.