Forum Discussion

tanny1234's avatar
tanny1234
New Member
4 years ago
Solved

URGENT - DAX - How to insert value based on below conditions

 I am required to add the value of column C based on the value of (column A & column B). The value has to be inserted based on below conditions -   First step -> Get VAR x = value of column[B] wher...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi tanny1234 

    Here I have two workarounds to achieve your goal.

    1. If your table looks like the screenshot, where the A columns with the same B values are arranged in the order of Mango and Apple, then you can try the Fill Up/Down function in the Power Query Editor.

    My Sample is the same like yours.

    Result is as below.

    2. Try Group By in Power Query Editor.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZA7DoAgDEDv0tlBfkJHD+AJiIODcTHK/SdbIJqCr0OTl5cOjRGW7TpuGECFEWnBOkSYUzr3zylEk/3bYp9m5QhZhvBzNbuJkbH3vouL84yMiS4uLmRErYm2rg4ZERuijauzjkfUlmjr6pQ2lh+yPg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t, C = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"A", type text}, {"B", Int64.Type}, {"C", Int64.Type}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"B"}, {{"Rows", each _, type table [A=nullable text, B=nullable number, C=nullable number]}}),
        #"Duplicated Column" = Table.DuplicateColumn(#"Grouped Rows", "Rows", "Rows - Copy"),
        #"Expanded Rows - Copy" = Table.ExpandTableColumn(#"Duplicated Column", "Rows - Copy", {"C"}, {"Rows - Copy.C"}),
        #"Grouped Rows1" = Table.Group(#"Expanded Rows - Copy", {"B", "Rows"}, {{"Max", each List.Max([#"Rows - Copy.C"]), type nullable number}}),
        #"Expanded Rows" = Table.ExpandTableColumn(#"Grouped Rows1", "Rows", {"A"}, {"Rows.A"}),
        #"Reordered Columns" = Table.ReorderColumns(#"Expanded Rows",{"Rows.A", "B", "Max"}),
        #"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Rows.A", "A"}, {"Max", "C"}})
    in
        #"Renamed Columns"

    For reference: Grouping or summarizing rows

     

    Best Regards,
    Rico Zhou

     

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