I have a set of data with this range 0-10, 11-20, 21-30, and exceed 30. My data was loaded to power BI using direct query.
I add column from selection in transform data. I was able to auto generate the range

This is the power query of that column:
= Table.AddColumn(TAPS_masterData, "Range", each let rangeSize = 10, offset = 0, inclusive = false, rangeIndex = Number.RoundDown(([PostingAge] - offset) / rangeSize) in Text.From(rangeIndex * rangeSize + offset, "en-US") & "-" & Text.From((rangeIndex + 1) * rangeSize + offset - (if inclusive then 1 else 0), "en-US"), type text)
But when i want to apply the changes, it shows below error: This step results in a query that is not supported in DirectQuery mode. Switch all tables to Import mode.
Your M code as written works fine
You can go to Power BI Desktop, go to Model view-->Advanced and change the storage mode from DirectQuery to Import