I am pretty new to Canvas app and I was actually looking for implementation of JS logic in power fx. Power fx is a low code language but its very complex while applying the logic to it when the filters are nested. Is there any way I could implement the following JS code in Power fx.
let Vehicles = [
{name:'foo bar', vehicleFeatures: ["Bow", "Feature2"]},
{name:'hello world', vehicleFeatures: ["Bow", "Row"]},
{name:'mind games', vehicleFeatures: ["Test"]},
{name:'new world', vehicleFeatures: ["Bow", "Row", "Feature3"]},
];
let selectedFeaturesToFilter = ["Bow", "Row"];
let filteredVehicles = Vehicles.filter(vehicle=>{
if(vehicle.vehicleFeatures.every(feature=>selectedFeaturesToFilter.includes(feature))){
return vehicle;
}
});
console.log(filteredVehicles);
In case of canvas app I have selectedFeaturesToFilter equivalent to the Combobox.SelectedItems and 'Vehicle' and 'Vehicle Features' are two tables with many to many relationship. I need to get the filteredVehicles.
Yes, you can do this with PowerFx. On your
App OnStart, create the data:Vehicles collection
Features filter
Filter vehicles with the desired features
Merge results
Now, as you have two features to filter, the collection
FilteredVehiclesCollectionhas two rows. If you want to have a single row with the filtered vehicles, you need to merge the rows. This code is tricky, but it's working:Screenshots