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

Rewriting formula DAX in the language M

Hi
Need help rewriting formula dax in the language m - add a custom column
my formula: Previous = LOOKUPVALUE('445'[datetime],'445'[Rank],'445'[Rank]-1)
goal: append two queries (with the participation of the column)
similar theme unanswered: 
http://community.powerbi.com/t5/Desktop/How-to-append-queries-to-calculated-columns/m-p/40520#U40520


It is also open to other solutions
Thank you

1 ACCEPTED SOLUTION
v-qiuyu-msft
Community Support
Community Support

Hi @BI2B,

 

In your scenario, you can use UI to generate the backend M query.

 

1. Add a index column from 0.

2. Add a custom column like below:

=AddInd[datetime]{[Index]-1}

3. Replace the error with null value.

4. The backend M query like below:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwNNM1NNI1VNJRAmMDpVgdhLARUAiMUYWNgUJgjCpsAhQCY6BwLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [datetime = _t, Rank = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"datetime", type date}, {"Rank", Int64.Type}, {"Amount", Int64.Type}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Rank", Order.Ascending}}),
    AddInd = Table.AddIndexColumn(#"Sorted Rows", "Index", 0, 1),
    #"Added Custom" = Table.AddColumn(AddInd, "Custom", each AddInd[datetime]{[Index]-1}),
    #"Replaced Errors" = Table.ReplaceErrorValues(#"Added Custom", {{"Custom", null}})
in
    #"Replaced Errors"

 

Reference:

Absolute and Relative References in Power Query: R1C1 Excel-style approach

How can I do calculation based on next/prior row in Power Query?

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-qiuyu-msft
Community Support
Community Support

Hi @BI2B,

 

In your scenario, you can use UI to generate the backend M query.

 

1. Add a index column from 0.

2. Add a custom column like below:

=AddInd[datetime]{[Index]-1}

3. Replace the error with null value.

4. The backend M query like below:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwNNM1NNI1VNJRAmMDpVgdhLARUAiMUYWNgUJgjCpsAhQCY6BwLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [datetime = _t, Rank = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"datetime", type date}, {"Rank", Int64.Type}, {"Amount", Int64.Type}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Rank", Order.Ascending}}),
    AddInd = Table.AddIndexColumn(#"Sorted Rows", "Index", 0, 1),
    #"Added Custom" = Table.AddColumn(AddInd, "Custom", each AddInd[datetime]{[Index]-1}),
    #"Replaced Errors" = Table.ReplaceErrorValues(#"Added Custom", {{"Custom", null}})
in
    #"Replaced Errors"

 

Reference:

Absolute and Relative References in Power Query: R1C1 Excel-style approach

How can I do calculation based on next/prior row in Power Query?

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Qiuyun,

Thank you very much for your help and solution Smiley Happy

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.