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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
kosukey05
Regular Visitor

Adding a new column referring to a column and value of next row.

Hello Power BI experts,

 

I'm new to power bi and trying to find a way to achive my requirment but couldnot find how to solve.

 

I want to visualize the movement of users.

 

I have this table.

 

userlocation
aaatokyo
aaaosaka
aaanagoya
aaahakone
aaakyoto
bbbsapporo
bbbnara
ccctokyo
ccchakone
cccosaka
dddosaka
dddtokyo

 

How I want to transform this table is 

userFromTo
aaatokyoosaka
aaaosakanagoya
aaanagoyahakone
aaahakonekyoto
bbbsapporonara
ccctokyohakone
ccchakoneosaka
dddosakatokyo

 

I need to add the next value of location into "to" as a new column, but user cannot be mixed. 

It would be great if anyone can suggest how I can achive this.

 

Thank you!

1 ACCEPTED SOLUTION
affan
Solution Sage
Solution Sage

Hi @kosukey05,

 

Considering that you have mentioned yourself a biggener level user of Power BI. I have used the information from @Greg_Deckler's blogpost to create a pbix for you.

FROM TO.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

You can create an Index column in your table by going to 'Edit Queries' and click on Index column in the Add Column tab on the ribbon.

Add Index.png

 

 

 

 

Once you have added an index you can use the below to add a calculated column as below. I have also attached a pbix file for this example which you can review.

 

To_Location = VAR fromLoc = MINX(FILTER(Table2,Table2[user]=EARLIER(Table2[user])&& Table2[Index]>EARLIER(Table2[Index],1)),Table2[Index])
    Return 
    CALCULATE(FIRSTNONBLANK(Table2[From_location],1),FILTER(Table2,Table2[Index]=fromLoc))

 

You can review the pbix file 

 

https://www.dropbox.com/s/4brimatrmndxy0h/FROM-TO%20Location.zip?dl=0

 

Please accept as solution if this helped.

 

Regards,

Affan

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

 

You may refer to my solution at this link.

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Ashish_Mathur
Super User
Super User

Hi,

 

I think i have been able to solve the problem.  Please allow me time until the weekend to share my solution with you.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@kosukey05 I've tried this to solve your scenario...

 

Added a new index column and "New Column" as below

 

To = LOOKUPVALUE(UserLocations[location],UserLocations[user],UserLocations[user],UserLocations[Index],UserLocations[Index]+1)

Looks something like this.... (Note - I've duplicated location field as From Field as well)

 

image.png

 

Then add a "New Table" which will be your expected output as below..

 

UserLocationsOutput = CALCULATETABLE(
                                 SELECTCOLUMNS(FILTER(ALL(UserLocations),NOT ISBLANK(UserLocations[To])),"User",UserLocations[user],"From",UserLocations[From],"To",UserLocations[To])
                                 )

image.png

 





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

Proud to be a PBI Community Champion




affan
Solution Sage
Solution Sage

Hi @kosukey05,

 

Considering that you have mentioned yourself a biggener level user of Power BI. I have used the information from @Greg_Deckler's blogpost to create a pbix for you.

FROM TO.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

You can create an Index column in your table by going to 'Edit Queries' and click on Index column in the Add Column tab on the ribbon.

Add Index.png

 

 

 

 

Once you have added an index you can use the below to add a calculated column as below. I have also attached a pbix file for this example which you can review.

 

To_Location = VAR fromLoc = MINX(FILTER(Table2,Table2[user]=EARLIER(Table2[user])&& Table2[Index]>EARLIER(Table2[Index],1)),Table2[Index])
    Return 
    CALCULATE(FIRSTNONBLANK(Table2[From_location],1),FILTER(Table2,Table2[Index]=fromLoc))

 

You can review the pbix file 

 

https://www.dropbox.com/s/4brimatrmndxy0h/FROM-TO%20Location.zip?dl=0

 

Please accept as solution if this helped.

 

Regards,

Affan

Greg_Deckler
Super User
Super User

Add an Index column in Power Query and then follow this article. See my article on Mean Time Before Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...


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

Fabric certifications survey

Certification feedback opportunity for the community.

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.