Forum Discussion

AugustoChaves's avatar
AugustoChaves
Icon for Advocate II rankAdvocate II
1 year ago
Solved

Strange Sorting Behavior in Power BI Calendar Table – year_month_short vs. month_year_short

Hi everyone, We’re seeing a strange issue in our Power BI semantic model and would appreciate any insights. We have a calendar table in our warehouse that includes two formatted string columns: y...
  • Deku's avatar
    1 year ago

    This is as expected. When you sort a column by another column, both are included in every query. This means you see the year month duplicate once per date. You really want to sort the column by a field that has the same frequency of change. The month end works since you only have a single value of month end per month. So you want to create a number field of year number and month number, which can be used as the sort by column

  • rohit1991's avatar
    1 year ago

    Hi AugustoChaves ,

    The behavior you're observing in Power BI with the year_month_short and month_year_short fields showing repeated values when sorted by calendar_date is actually expected due to how Power BI's "Sort by Column" functionality works. When you set a column (like year_month_short) to be sorted by another column (like calendar_date), Power BI includes both fields in the query context.

     

    Since calendar_date is at the daily granularity and your formatted strings represent monthly granularity, Power BI displays a row for each date, causing apparent duplication of month names.

    Your observation that sorting by a column like month_end resolves the issue makes sense — that field likely has one unique value per month, aligning with the granularity of your display fields. The best practice here is to create a numeric column that represents the month in a sortable way — for example, a YYYYMM integer (like 202812 for December 2028) — and use that as your “Sort by Column”. This keeps the frequency of change consistent between the display column and the sort column, avoiding unnecessary duplication.