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
SusD
Frequent Visitor

How to copy a value from one row to another based on unique ID

Dear all 

 

First of all thanks for helping me out. I've been struggling with this issue for quite some time and I do not seem to be getting a satisfactory result. 

 

The question goes as follows: I'm getting some filled in questionnaires through an SQL server and the data that comes in is rather unpolished. The questionnaire is built out of two parts. One in which you fill in a simple MC question (good, bad, perfect...) and one in which you can go a bit more into detail. Both questions are linked to a unique id. The number of rows is dependant on the input and is therefore variable. The problem is that for the analytical purposes, the answer to the MC question needs to come back in the other part. Even though I tried explaining it as good as possible, I've added some screenshot to provide clarity 🙂 

 

I've found a potential solution on the forum which stated that grouping might work. I've tried it and even though it works, the dataset is too slow to work with after I've done it and I got complaints from the ITC department that I was clogging the server. The dataset I'm currently working in is around 200.000 rows and 50 columns. The one below is of course simplified. 

 

Thanks a lot! 

Sus

 

SusD_0-1613126765480.png     SusD_1-1613126825641.png

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@SusD , Create a new  column like this in DAX

maxx(filter(Table, [ID] = earlier([ID])),[Score])

View solution in original post

6 REPLIES 6
PhilipTreacy
Super User
Super User

Hi @SusD 

Download sample PBIX with this data and code

Are these ID's always the same with the same assigment i.e. is 22000 always Good, is 22001 always Perfect etc?

If you know the ID and what text string to assign it then you could do this in Power Query by creating a Custom Column

 

= if [ID] = 22000 or [ID] = 37800 then "Good" else if [ID] = 22001 then "Perfect" else "Bad"

 

 

Or better to do it in DAX using a measure

 

Score = 

VAR _ID = SELECTEDVALUE('Table'[ID])

RETURN

SWITCH(

    TRUE(),   

    _ID = 22000 || _ID = 37800, "Good",

    _ID = 22001, "Perfect",

    _ID = 23000, "Bad",

    ""
)

 

 

 

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi Philip, 

Unfortunately this is not the case. I have around 200.000 unique IDs and they are not linked to the result. 

 

Thanks for the help! 

amitchandak
Super User
Super User

@SusD , Create a new  column like this in DAX

maxx(filter(Table, [ID] = earlier([ID])),[Score])

Any idea on how to do the same solution in power query?

Except Fill Up and Down.

Quick update:

I'm realising now that it was a calculated column. Working like a charm now. Thanks!

Hi there, 

Thanks for the help! However, I do seem to be getting an expression error. Any idea what might be causing the issue? I've added printsceeen with updated column names.  

 

SusD_0-1613129287083.png

 

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.