Forum Discussion
gomorasa
1 year agoNew Member
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...
- 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.
Anonymous
1 year agoNot applicable
Thanks for the reply from adudani , please allow me to provide another insight:
Hi gomorasa ,
Here are the steps you can follow:
1. Create calculated column.
Test =
var _COUNTABC=
CALCULATE(
DISTINCTCOUNT([Product group]),FILTER(ALL('Table'),[Customer]=EARLIER([Customer])&&[Product group] in {"Product group A","Product group B","Product group C"}))
var _COUNTOTHER=
CALCULATE(
DISTINCTCOUNT([Product group]),FILTER(ALL('Table'),[Customer]=EARLIER([Customer])&&NOT([Product group]) in {"Product group A","Product group B","Product group C"}))
RETURN
SWITCH(
TRUE(),
_COUNTABC>=1&&_COUNTOTHER=BLANK(),"Direct Revenue",
_COUNTABC>=1&&_COUNTOTHER>=1,"Indirect Revenue")
2. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly