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
"It didn't work"
Great. That really is a lot of information to help in looking for the problem
If you just replicated what I did it should work. You are using " minutes"
Number.FromText(Text.BeforeDelimiter([#"Metrou"]," minutes")
Don't you need to adapt that to the language you are using?
Like I said earlier, explain what does not work. Or isolate the several steps in the code to pinpoint which one is not working. Or share the actual pbix or one with dummy data that reproduces the problem
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 AlB
Sorry about the lack of details. It's my first message here and I am rather new in working with Power BI.
I've created a pbix file that I am sending here (can't upload it directly)
The first problem was, as you mentioned, not transforming "minutes" to "minute". Now, the 2nd issue has to do with distance to the metro - I actually used a faulty example because in my file, I have intervals of time (e.g. 5-10 minutes), so most probably, this is the last remaining issue.
Also, for the other way round (number of persons that suit each apartment) I should use the same formula?
This is the link to the pbix file
Thank you for your help and I appologize again for my inexactities
Mihai