Forum Discussion

gomorasa's avatar
gomorasa
New Member
1 year ago
Solved

Dax help

Good day can anyone assist with the following dax measures for the following problem statement : i have also attached a data sample, i would also like to create a calculated column to flag Preferred...
  • adudani's avatar
    1 year ago

    hi gomorasa ,

    create a blank query. open the advanced editor. copy and paste the code below:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rZPLbsIwEEV/xUo3VHKj8SOOsyyIVl0UUVFWiEUEbhsJYpQ4C/6+kyBDQIg2aRdxri3rzJ2HF4tgZLe7NN+TkV2bgAZPWblKN2RqisyucT8t7LpaOfJZ2GqH+9lXtnt4t3i9yl2xx5NRVTq7NQXKYVoaMs8zR+wHeTVpWRU1861Kc5e5+vLEuFm6MSXKYEkXQSQAULNWpOc6EhnjyXyGi5BCKYFi/IiLghAASKOlpkLLsAH8EsYAGEs08zjZwnGKsi/tDr+Ghf+BJ933Nyag5Sym0U/OmvaQ4REXJSAleBo7sRjVPVhCX2OJXr4OrLOCedCtgl2QEi4gUVcT5FE3U39BXbYxZkoqWT+Fl4nPkBz0QAgRRp2G4haNawhVxxEDHovT7OtWpjEPdbfJ96yzRh44/2SKU9n1QUaaM9AeBp1G9cqL5ELHx+o/KH3eAIqxjkO7/AY=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t, Column9 = _t]),
        #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"NetSales", type number}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "(Non/)Preferred Customer Flag", each if Text.Contains([Product group],"A") and [NetSales] >0 or 
    Text.Contains([Product group],"B") and [NetSales] >0 or 
    Text.Contains([Product group],"C")  and [NetSales] >0 then "Preferred Customers"
    else "Non Preferred")
    in
        #"Added Custom"

     

    the flag is based on the logic below. if sales > 0 and prod groups contain A , B or C , then preferred else not preferred.

     

    if this isn't the required logic, kindly elaborate and provide a sample output.