Forum Discussion
SzEmo
4 years agoNew Member
Converting DAX to M
Dear All, Could you please help me with converting the following DAX statement to PowerQuery (M)? = CALCULATE( SUM(Database[Column1]), Database[Column2] IN {"C/R", "no"}, Database[Column3...
- 4 years ago
Hi SzEmo ,
Maybe you can try this code:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXLWDwKS/gGufkAKJODrGKLrqhSrE61kBJd29vEPdnUBMoxQFBgDeXn5mNpTwLImMFm4blTjTYG8ytRihHZUw83g0hj6gebHAgA=", 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]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", type text}, {"Column3", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "if", each if List.Contains({"C/R","no"},[Column2]) and List.Contains({"OPEN","CLOSED"},[Column3]) and List.Contains({"1"},[Column4]) and List.Contains({"MAT-E"},[Column5]) then 1 else 0), #"Grouped Rows" = Table.Group(#"Added Custom", {"if"}, {{"sum", each List.Sum([Column1]), type nullable number}}), #"1" = #"Grouped Rows"{[#"if"=1]}[sum] in #"1"Best Regards
Community Support Team _ chenwu zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-chenwuz-msft
4 years agoCommunity Support
Hi SzEmo ,
Maybe you can try this code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXLWDwKS/gGufkAKJODrGKLrqhSrE61kBJd29vEPdnUBMoxQFBgDeXn5mNpTwLImMFm4blTjTYG8ytRihHZUw83g0hj6gebHAgA=", 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]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", type text}, {"Column3", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "if", each if List.Contains({"C/R","no"},[Column2])
and List.Contains({"OPEN","CLOSED"},[Column3])
and List.Contains({"1"},[Column4])
and List.Contains({"MAT-E"},[Column5])
then 1 else 0),
#"Grouped Rows" = Table.Group(#"Added Custom", {"if"}, {{"sum", each List.Sum([Column1]), type nullable number}}),
#"1" = #"Grouped Rows"{[#"if"=1]}[sum]
in
#"1"
Best Regards
Community Support Team _ chenwu zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.