Forum Discussion

Yonas's avatar
Yonas
Microsoft Employee
6 years ago
Solved

How to create a caluculated column using dax

I have two columns name and retention days, I want to create a calculated column which checks" For each name check if there is a retention day value>30, if there is "Yes" else "No" my sample data ...
  • HotChilli's avatar
    6 years ago
    Column = IF (CALCULATE(MAX(TableXX[Retention days]), ALLEXCEPT(TableXX, TableXX[Name])) > 30  , "Yes", "No")
  • dax's avatar
    6 years ago

    Hi Yonas , 

    You also could try below M code to achieve this goal

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjNU0lEyNFCK1YGyjU0RbCOouBFIjSmCjSxuBBSPBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [name = _t, #"retention day" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"name", type text}, {"retention day", Int64.Type}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"name"}, {{"max", each List.Max([retention day]), type number}, {"all", each _, type table [name=text, retention day=number]}}),
        Custom1 = Table.ReplaceValue(#"Grouped Rows", each  [max], each if [max]>30 then "Yes" else "No", Replacer.ReplaceValue, {"max"}),
        #"Expanded all" = Table.ExpandTableColumn(Custom1, "all", {"retention day"}, {"retention day"})
    in
        #"Expanded all"


    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.