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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

DAX Formulas transform Power Query M Formulas

Hi There,

 

I have added a column with DAX formulas on front side in Power BI desktop like this:

 

Last Choice= 

VAR _lastIndex = CALCULATE( 
    MAX( 'answers'[_id] ), 
    ALLEXCEPT( 'answers', 'answers'[UserID], 'answers'[QuestionDescription])
)
RETURN CALCULATE( 
    SELECTEDVALUE( 'answers'[AnswerText] ), 
    ALL( 'answers' ),
    'answers'[_id] = _lastIndex 
)

 

But I want to create this column in power query side. How can we do that?

 

Best,

6 REPLIES 6
Anonymous
Not applicable

Hi @StefanoGrimaldi ,

 

I don't have an ID column to sort, I have ID column like this:

ID

5f563e7c2a0b587e1db5ebd7

5f576bc72a0b587e1dbcaf0d

5f563e7c2a0b587e1db5ebd8

5f576bc72a0b587e1dbcaf0c

That is MongoDBs ObjectID.

 

And I need Last AnswerText for user and questiondescription. so I need a column as this:

UserID QuestionDesc. LastAnswer

user1  question1 answer2

user1 question2 answer1

user2 question1 answer3

any other field you can get  or extract from the source? since you would need a reference to us as registration order, or to make a index column to be able to get the last entry per user. for example: if the answer are called to your table in registration order you can simply add an index column starting by 0 and them follow the above steps, if not the case them you will need a column source that give your this cronological order data. 





Did I answer your question? Mark my post as a solution! / Did it help? Give some Kudos!

Proud to be a Super User!




StefanoGrimaldi
Resident Rockstar
Resident Rockstar

yes can be done, for what Im seeing (Please correct me if mistaken)  each new response generate a new ID lets says A1 +1, A2+1 and so on, so the last number of your column gives you what you need to sort the responses in order, for this go to the home tab in power query interface and use the split column option, sinces your ID always beggins with a A followed by a number use the option of spliting by number of characters from right to left by 1 

StefanoGrimaldi_0-1608903867282.pngStefanoGrimaldi_1-1608903881719.png

if you need the original ID column as its , duplicate it before splitting. 

 

them change the column left with number to number type, and sort it in order from lower to biggest to get it in order, them use the Index fuction to add a index to allocate a order finally. 

 

with thois you would have your data in cronological order, now your example shows me you want them to add a column with the last user response,

 

them you can use the group by function to make this happend: 

 

StefanoGrimaldi_0-1608911414090.png

 

let me know if this works for your need





Did I answer your question? Mark my post as a solution! / Did it help? Give some Kudos!

Proud to be a Super User!




as you need it as a column you can make this a second table and disable the loading of it, and in a new table without the group by step you can use a merge fucntion to call this as a new column, like this:

StefanoGrimaldi_1-1608911571416.pngStefanoGrimaldi_2-1608911594351.png

 





Did I answer your question? Mark my post as a solution! / Did it help? Give some Kudos!

Proud to be a Super User!




Anonymous
Not applicable

Hi @StefanoGrimaldi 

 

Thank you for your response but I need actually a new column. If you say me how can I add a new column in Power Query ediyor, that's enough for me. I try to explain what I need below:

 

I have a table like this:

 

Ekran Alıntısı.PNG

 

 

 

 

 

 

 

 

 

 

 

I need a Last Choice column Like this table:

 

Ekran Alıntısı2.PNG

 

 

 

 

 

 

 

 

 

 

 

I dont have date for this. We can sort this data only for id. I dan do it in DAX but I need it in power query.

 

I hope It can be done.

 

Best,

StefanoGrimaldi
Resident Rockstar
Resident Rockstar

You can sort by the date in power query then add the index so th index 0 would be always index 0 then filter the index column for only value 0, 

Power Query M code:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tci5DQAxDAOwXVwHUCw/ywQZ4fZvT0UKs+Q59rUtazS4ue0ujWscPoYagmNCE4gxqUnkmNIU6s39AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [data = _t, date = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"data", type text}, {"date", type date}}),
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"date", Order.Descending}}),
#"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 0, 1, Int64.Type),
#"Filtered Rows" = Table.SelectRows(#"Added Index", each ([Index] = 0))
in
#"Filtered Rows"

StefanoGrimaldi_0-1608821507048.png

 

initial table: 

 

Result: 

 

StefanoGrimaldi_1-1608821531963.png

 If this have solved your problem Please mark it as a solution, so others can find this solution quickly, If you found this post helpful, please give Kudos.

 





Did I answer your question? Mark my post as a solution! / Did it help? Give some Kudos!

Proud to be a Super User!




Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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