I’m providing some of the links of the videos, blog posts as well as the solution that was provided on the Power BI Community Forum for the similar sort of the query. About how this can be achieved via Power Query as well through DAX.
Hoping you find this useful and helps you in your analysis.