I can explain the reason for the message and why you are not able to delete the main account, but unfortunately cannot give you a good solution for how to fix it.
When you add new records to financial dimension entities (Main account, Department, Cost center, etc.), they are merely available for use and can be immediately deleted. However, as soon as they are actually used, additional records are created in tables such as DimensionAttributeValue, DimensionAttributeValueCombination, DimensionAttributeLabelValue, and many others. Even if you then delete the journal line (presumably) that referenced the new Main account, the fact that you have ever used it means that these records will exist forever. AX provides no mechanism for deleting these records. The only method would be with direct SQL, and the schema behind those tables is rather complicated.
I just yesterday had to solve this exact problem, where someone added and subsequently used and immediately deleted a whole bunch of Departments that should have been Cost centers. I was able to delete all of the supporting records, verify that no damage was done to any other references across all AX tables, and then delete the Departments from the UI. It is not a task to be taken lightly, and I would never post that SQL for use by someone who didn't understand the risks deeply.
second answer by
Hi Katrin,
Read the answer of Brandon very carefully. One of the checks for a main account being used is done on the table "DimensionValueAttributeCombination". You can search for the main account in this table and delete the records. Then also the main account itself can be deleted.
You have to be very sure it is not used elsewhere. Note that within Brandons answer it is stated that there are more tables part of the dimension framework. When you delete records in this table, other tables might have records that should be removed as well. I have not noticed problems if only the appropriate records in the mentioned table are deleted.
Another note: It is possible if you have multiple charts of accounts or e.g. fixed assets or dimension values with the same value as your main account, you can delete wrong records!