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
konradjonsson
Helper II
Helper II

Translate DAX to Power Query M language

Hi.

 

I need help to translate the following DAX formula into a M formula in Power Query.

 

1MONTH WTY = if(DATEDIFF('Table'[Invoice Date];max(Table'[Invoice Date]);day)>31;'Table'[1mth];BLANK())

 

I have tried the following, but it gives an error as result (no issue with the syntax, it is the output that is erroneous):

#"Added Custom" = Table.AddColumn(#"Changed Type4", "1MONTH WTY", each if Duration.Days(Duration.From(Table.Max[Invoice Date] - [Invoice Date]))>31 then [#"1mth"] else "")

2 ACCEPTED SOLUTIONS
Mariusz
Community Champion
Community Champion

Hi @konradjonsson 

 

Try something like this

    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each 
        let 
            durat = Duration.Days( List.Max( #"Changed Type"[Invoice Date] /* this is the previous step */) - [Invoice Date] ) > 31, 
            output = if durat then  [#"1mth"] else "" 
        in 
            output
    )

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

 

View solution in original post

dax
Community Support
Community Support

Hi konradjonsson, 

You could refer to below M code to see whether it work or not

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZcvLCQAgEAPRXvYsJFlQtBax/zZUPPi7PmZqNacK5EgWzFrYEF8Qh+ggweNPs+JB/Efi+TJ0X3lNQ1oH", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [date = _t, M1mth = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"date", type date}, {"M1mth", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Duration.Days(Duration.From(List.Max(#"Changed Type"[date])-[date]))>31 then [M1mth] else null)
in
    #"Added Custom"

 

 

Best Regards,
Zoe Zhi

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

4 REPLIES 4
dax
Community Support
Community Support

Hi konradjonsson, 

You could refer to below M code to see whether it work or not

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZcvLCQAgEAPRXvYsJFlQtBax/zZUPPi7PmZqNacK5EgWzFrYEF8Qh+ggweNPs+JB/Efi+TJ0X3lNQ1oH", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [date = _t, M1mth = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"date", type date}, {"M1mth", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Duration.Days(Duration.From(List.Max(#"Changed Type"[date])-[date]))>31 then [M1mth] else null)
in
    #"Added Custom"

 

 

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Mariusz
Community Champion
Community Champion

Hi @konradjonsson 

 

Try something like this

    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each 
        let 
            durat = Duration.Days( List.Max( #"Changed Type"[Invoice Date] /* this is the previous step */) - [Invoice Date] ) > 31, 
            output = if durat then  [#"1mth"] else "" 
        in 
            output
    )

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

 

Mariusz
Community Champion
Community Champion

Hi @konradjonsson 

 

Can you create a small data sample?

 

Thanks

Mariusz

Hi.

I am not so savy on uploading table data. I attach a snapshot, where I have highlighted the issue in red.

DAX vs M.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.

Top Solution Authors