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
Anonymous
Not applicable

Transform a column with a logic

Hello everyone! 

 

I have a problem that can be simplified as follows:

 

There is a table, with a column named "a" with values [1,0,1,0,0,0,1,0,0,1,0,1] and I want to create another column "b" that will be [1,2,1,2,3,4,1,2,3,1,2,1]. The logic to build that column is:

 

If the value of a in a certain position is 1, the value of b in the same position is 1.
Between two different ones, there is to index that succession as it is shown in the example.
I'd appreciate any help! Thanks.

1 ACCEPTED SOLUTION
PattemManohar
Community Champion
Community Champion

@Anonymous  Please try the below steps:

 

Step 1 : In Power Query Editor, please add an Index Field and Call it as MainIndex

 

image.png

 

Step 2 : Split the Data column using "Split Column" option as below

 

image.png

 

Step 3 : Now again, add an another Index field and call it as SubIndex

 

image.png

 

Step 4 : Now back to Report view, add an additional column using DAX as below

 

CalcColumn = 
VAR _Prev1SubIndex = CALCULATE(MAX(Test230FunnySplit[SubIndex]),FILTER(ALL(Test230FunnySplit),Test230FunnySplit[Data]=1 && Test230FunnySplit[MainIndex] = EARLIER(Test230FunnySplit[MainIndex]) && Test230FunnySplit[SubIndex] < EARLIER(Test230FunnySplit[SubIndex])))
RETURN IF(Test230FunnySplit[Data]=1,Test230FunnySplit[Data],(Test230FunnySplit[SubIndex] - _Prev1SubIndex)+1)

image.png

 

Step 5 : We have achieved the desired output but in row format, need to combine these back. So create a New Table as below

 

Test230Out = SUMMARIZECOLUMNS(Test230FunnySplit[MainIndex],"Data",CONCATENATEX(Test230FunnySplit,Test230FunnySplit[Data],",",Test230FunnySplit[SubIndex])
                                                          ,"CalcColumn",CONCATENATEX(Test230FunnySplit,Test230FunnySplit[CalcColumn],",",Test230FunnySplit[SubIndex])
                             )

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




View solution in original post

2 REPLIES 2
PattemManohar
Community Champion
Community Champion

@Anonymous  Please try the below steps:

 

Step 1 : In Power Query Editor, please add an Index Field and Call it as MainIndex

 

image.png

 

Step 2 : Split the Data column using "Split Column" option as below

 

image.png

 

Step 3 : Now again, add an another Index field and call it as SubIndex

 

image.png

 

Step 4 : Now back to Report view, add an additional column using DAX as below

 

CalcColumn = 
VAR _Prev1SubIndex = CALCULATE(MAX(Test230FunnySplit[SubIndex]),FILTER(ALL(Test230FunnySplit),Test230FunnySplit[Data]=1 && Test230FunnySplit[MainIndex] = EARLIER(Test230FunnySplit[MainIndex]) && Test230FunnySplit[SubIndex] < EARLIER(Test230FunnySplit[SubIndex])))
RETURN IF(Test230FunnySplit[Data]=1,Test230FunnySplit[Data],(Test230FunnySplit[SubIndex] - _Prev1SubIndex)+1)

image.png

 

Step 5 : We have achieved the desired output but in row format, need to combine these back. So create a New Table as below

 

Test230Out = SUMMARIZECOLUMNS(Test230FunnySplit[MainIndex],"Data",CONCATENATEX(Test230FunnySplit,Test230FunnySplit[Data],",",Test230FunnySplit[SubIndex])
                                                          ,"CalcColumn",CONCATENATEX(Test230FunnySplit,Test230FunnySplit[CalcColumn],",",Test230FunnySplit[SubIndex])
                             )

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




Anonymous
Not applicable

Amazing solution! Thank you very much.

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.