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

Shape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.

Reply
sarah2
Helper II
Helper II

Customize Formula - M code

Hello! I posted on here with an issue I was having and a kind person responded with a solution that looked like it would work. I accepted the solution because I didn't have time to work on it right away and wanted to make sure they got the credit for it but when I went back later I realized I don't know how to adjust the code for my data. I'm new to M code so looking for help on what parts need to be edited to work in my data set. 

 

Here's the code: 

let
    T1RawData = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwVNJRcitKzEtOBTJCUhNzFRyBjEgg9ixJzVUwUorVASkzJk6ZCVHKLCwJKosFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Session ID" = _t, Business = _t, Staff = _t, #"Question 1 " = _t, #"Question 2" = _t]),
    T2EditTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwVtJRcnH1cQ1xBTIUUHCsDkiBCZTvWZKYU4kpb2GJJBaSmpir4AzXkJqrYKwUGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Session ID" = _t, Delete = _t, Business = _t, Staff = _t, #"Question 1" = _t, #"Question 2" = _t]),
    // You can probably delete this step when applying on real data.
    T2ReplaceBlankToNull = Table.TransformColumns(T2EditTable, {}, each if Text.Trim(_) = "" then null else _),
    MergedQueries = Table.NestedJoin(T1RawData, {"Session ID"}, T2ReplaceBlankToNull, {"Session ID"}, "T2", JoinKind.LeftOuter),
    Ad_Updated = Table.AddColumn(MergedQueries, "Updated", each 
        [ a = Record.FromTable(Table.SelectRows(Record.ToTable([T2]{0}?), (x)=> x[Value] <> null)),
          b = if Text.Upper([T2]{0}?[Delete]?) = "DELETE" then null else _ & (try a otherwise []),
          c = try Table.RemoveColumns(Table.FromRecords({b}), {"T2"}) otherwise null
        ][c], type table),
    CombinedUpdated = Table.Combine(List.RemoveNulls(Ad_Updated[Updated]), Value.Type(T1RawData))
in
    CombinedUpdated

 

Feel free to comment here or on the originial post but I'm looking for what parts do I edit to change the document names (the two are uploaded in the same Power BI) and what is the note "You can probably delete this step when applying on real data" refer to?

 

Thank you so much for your help!

5 REPLIES 5
Omid_Motamedise
Memorable Member
Memorable Member

What is the main goal of this function?

The originial thread is here: https://community.fabric.microsoft.com/t5/Power-Query/Separate-workbook-to-guide-dynamic-changes/m-p...

 

The goal is to have a table that can edit the raw data on the power query side

lbendlin
Super User
Super User

Do you have tow tables called RawData and EditTable ?

Yes, there are two tables and those can be the names. I don't want them to be static like the code without editing it (it's on real data)

Here's the link to the original thread: https://community.fabric.microsoft.com/t5/Power-Query/Separate-workbook-to-guide-dynamic-changes/m-p... 

Your requirement is not clear to me.

 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.