There's quite a lot to cover here, but I'll try and be brief!
The output array (value) from your Get emails action should go into a Filter array action. The filter condition being subject contains AIS
Now the output of that should go into a Select. Press the button to convert from key-value input into JSON mode, and in the box, add the expression substring(item()?['Subject'], indexOf(item()?['Subject'], 'AIS'), 7)
This will result in a single column array of your AIS numbers, many will be duplicated.
Now, add a compose and in there, go union(body('Select'),body('Select')). This dedupes the array into a set of unique AISRefNum values.
Next, add an Apply to each and put this de-duped array into its input, so you get one iteration per distinct AIS number
Inside the Apply to each, add a Filter array (it'll be called Filter array 2 for the sake of this example). Filter the non-deduped version of the array (the original Select action output) for item() equals items('Apply_to_each'). So you're filtering the non-deduped array for the value of the current iteration of the loop. The result will have one or more items of identical AIS numbers.
You can count those items with the length() function on the result. Add a Compose to do this (let's call it Compose 2) and set it like {"AISRefNo": "@{items("Apply_to_each")}", "Number of Emails": @{length(body('Filter_array_2'))}} where @{} denotes an expression and everything else is just typed directly into the Compose input.
What you're doing here is making a JSON object with two properties, one called AISRefNo with the value of the current iteration of the loop, and another called Number of Emails with the count of matching ref numbers from the non-deduped array from earlier.
Finally outside the Apply to each loop, do a Compose and add the expression outputs('Compose_2'). This will result in an array you can then run through the Create HTML Table function or whatever you want to do with it.