Forum Discussion
Count with multiple criteria
- 5 years ago
Hi mihai_enache
Can be done in DAX as well following a similar logic. Here is a possible solution in M, where ApartmentsT is the name of your apartments table. See it all at work in the attached file.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0AAIg7aij4KSj4Kyj4AIS1FEwAlKmCrmZeaUlqcVKsTrRSmARuGJXHQUvHQVvkGIQRlVqDBQyhiiFGgrUABIDW4ii1ASrGxDK8/JLFDJzC/KLShLzSsA6TEE6DBEOASnUUTDBqtYMKGqOMBzqNR0FqAZkt8QCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"User ID" = _t, Budget = _t, Neighbourhoods = _t, #"Number of rooms" = _t, #"Proximity to metro station" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"User ID", Int64.Type}, {"Budget", Int64.Type}, {"Neighbourhoods", type text}, {"Number of rooms", type text}, {"Proximity to metro station", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Numb apartments meeting criteria", each Table.RowCount(Table.SelectRows(ApartmentsT, (inner)=> inner[Price]<=[Budget] and Text.Contains([Neighbourhoods], inner[Neighbourhood]) and Text.Contains([Number of rooms], Text.From(inner[Number of rooms])) and (if [Proximity to metro station] = "not important" then true else if inner[Proximity to metro station]="out of range" then false else if Number.FromText(Text.BeforeDelimiter(inner[Proximity to metro station]," minutes")) <= Number.FromText(Text.BeforeDelimiter([Proximity to metro station]," minutes")) then true else false)))) in #"Added Custom"Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
- 5 years ago
Try this for the custom column
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Table.RowCount(Table.SelectRows(Apartamente, (inner)=> inner[#"Pret cu TVA calculat"]<=[#"Buget maxim disponibil"] and (if [#"Zone de interes:"]=null then true else if inner[#"Zona"]=null then false else Text.Contains([#"Zone de interes:"], inner[#"Zona"])) and Text.Contains([#"Cauti un apartament cu ..... camere"], Text.From(inner[#"Numar camere (numar)"])) and (if List.Contains({null,"nu este important"},[#"Distanta metrou (bifeaza optiunea maxim acceptabila): "]) then true else if inner[#"Distanta fata de metrou"]="Peste 20 minute" then false else if inner[#"Distanta fata de metrou"] = "peste 20 minute" then false else if Number.FromText(List.Max(Text.Split(Text.BeforeDelimiter(inner[#"Distanta fata de metrou"]," minute"),"-"))) <= Number.FromText(List.Max(Text.Split(Text.BeforeDelimiter([#"Distanta metrou (bifeaza optiunea maxim acceptabila): "]," minute"),"-"))) then true else false ))))You might have to tweak a bit to adapt it to your requirements completely. See it in the attached file
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
Hi mihai_enache
Can be done in DAX as well following a similar logic. Here is a possible solution in M, where ApartmentsT is the name of your apartments table. See it all at work in the attached file.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0AAIg7aij4KSj4Kyj4AIS1FEwAlKmCrmZeaUlqcVKsTrRSmARuGJXHQUvHQVvkGIQRlVqDBQyhiiFGgrUABIDW4ii1ASrGxDK8/JLFDJzC/KLShLzSsA6TEE6DBEOASnUUTDBqtYMKGqOMBzqNR0FqAZkt8QCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"User ID" = _t, Budget = _t, Neighbourhoods = _t, #"Number of rooms" = _t, #"Proximity to metro station" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"User ID", Int64.Type}, {"Budget", Int64.Type}, {"Neighbourhoods", type text}, {"Number of rooms", type text}, {"Proximity to metro station", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Numb apartments meeting criteria", each Table.RowCount(Table.SelectRows(ApartmentsT,
(inner)=> inner[Price]<=[Budget] and Text.Contains([Neighbourhoods], inner[Neighbourhood])
and Text.Contains([Number of rooms], Text.From(inner[Number of rooms]))
and (if [Proximity to metro station] = "not important" then true else if inner[Proximity to metro station]="out of range" then false
else if Number.FromText(Text.BeforeDelimiter(inner[Proximity to metro station]," minutes")) <= Number.FromText(Text.BeforeDelimiter([Proximity to metro station]," minutes")) then true else false))))
in
#"Added Custom"
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
Hello AlB ,
Thanks so much for your answer. I see it is working on your side but I didn't manage to replicate the model in my tables.
Some more details of what I did:
1. I brought through calculated columns the "proximity to metro" and "neighbourhood" into the apartments table (as the information is in a 3rd table named residential projects)
2. In the Users table, I tried to create a new column with the exact code you used and changing the names of the columns, but it didn't work
This is the code I used:
Table.RowCount(Table.SelectRows(#"Apartamente (2)",
(inner)=> inner[#"Pret cu TVA calculat"]<=[#"Buget maxim disponibil"] and Text.Contains([#"Zone de interes:"], inner[#"Zona"])
and Text.Contains([#"Cauti un apartament cu ..... camere"], Text.From(inner[#"Numar camere (numar)"]))
and (if [#"Distanta metrou (bifeaza optiunea maxim acceptabila): "] = "nu este important" then true else if inner[#"Metrou"]="Peste 20 minute" then false
else if Number.FromText(Text.BeforeDelimiter(inner[#"Distanta metrou (bifeaza optiunea maxim acceptabila): "]," minutes")) <= Number.FromText(Text.BeforeDelimiter([#"Metrou"]," minutes")) then true else false)))
Can you please tell me what I did wrong?
Thank you so much for your help
Mihai