Forum Discussion

jzadok's avatar
jzadok
Frequent Visitor
11 months ago
Solved

Group By fx in PBI Power Query does not group all duplicates as with Excel Power Query.

All - I have been doing some research on a Group By issue and have yet to find a solution...In Power BI, when performing the Group By function, I find that not all the duplicate values are uniquely grouped with corrsponding counts as they do in Power Query (Excel). My thinking is that performing the same function with the same data would produce the same result in both PBI and Excel. 

 

Curious if anyone here has ever run into this scenario and knows of a solution in PBI that will provide the expected outcome. 

 

Any help here would be greatly appreciated. 

 

 

  • Hi jzadok,

    Thanks for sharing your custom trim function, that is a great approach. If you are still seeing differences, it is usually due to hidden characters or casing that Excel strips but Power BI keeps. You can try wrapping your column with:

    Text.Upper(Text.Clean(Text.Trim([YourColumn])))

    This should standardize spaces, remove hidden characters, and align grouping with what you see in Excel.

    Let us know if that works out. Let us know if you have any doubts regarding this. We will be happy to help.

    Thank you for using the Microsoft Fabric Community Forum.

9 Replies

  • That does not happen unless there is something different about your data (or possibly or code) in the two versions. If you could share the *.pbix file that demonstrates the non-grouping (along with the data source if it is separate from the .pbix file), I may be able to assist.

  • Can you please share the data that you are using? Power Query behaves the same in Excel, Power BI and Dataflows.

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Icon for Community Champion rankCommunity Champion

    maybe there are some unseeable charactor. try this code in your PBI PQ editor

    =Table.Group(YourTable,"name",{"Count",Table.RowCount},1,(x,y)=>Vaule.Compare(Text.Clean(x),Text.Clean(y)))

  • Hi jzadok,

    Thank you for reaching out to the Microsoft Fabric Community Forum. Also, thanks to wdx223_Danielaudreygerredtayloramyronrsnfld, for his inputs on this thread.

    I can understand why it feels confusing to see Group By behave differently between Excel and Power BI, especially when you are expecting identical outcomes with the same data. 

    The difference comes down to how Power BI handles text values under the hood. In Power BI, values that look identical may still contain small differences (for example trailing spaces, hidden/non-printable characters, or even variations in letter casing). These subtle differences can prevent Group By from combining the rows, while Excel tends to normalize them more aggressively, which is why you are seeing a mismatch. 

    To align Power BI with Excel, you can clean and standardize your column before applying Group By. A few quick transformations in Power Query usually solve it:
    • Trim → removes leading/trailing spaces
    • Clean → removes hidden/non-printable characters
    • Format (Lowercase/Uppercase) → ensures consistent casing if needed

    Refer these links:
    1. https://learn.microsoft.com/en-us/powerquery-m/text-trim 
    2. https://learn.microsoft.com/en-us/powerquery-m/text-clean 
    3. https://learn.microsoft.com/en-us/powerquery-m/text-functions 
    4. https://learn.microsoft.com/en-us/power-query/power-query-ui 

    Once you apply these steps and then run Group By, your results should match what you see in Excel.

    Hope this clears it up. Let us know if you have any doubts regarding this. We will be happy to help.

    Thank you for using the Microsoft Fabric Community Forum.

    • jzadok's avatar
      jzadok
      Frequent Visitor

      Thank you for the input. I nest a trim function/parameter (see below) in Table.TransformColumns as a general rule of thumb and best practice before working with the data. 

       

      let
      Source = (InputText as text) =>

        let

        Trimdata = Text.Combine(
        List.Select(
        Text.Split(
        Text.Trim(InputText), " "),
        each _ <> ""
        ),
        " "
        )

        in
        Trimdata
      in
      Source

      • v-kpoloju-msft's avatar
        v-kpoloju-msft
        Icon for Community Support rankCommunity Support

        Hi jzadok,

        Thanks for sharing your custom trim function, that is a great approach. If you are still seeing differences, it is usually due to hidden characters or casing that Excel strips but Power BI keeps. You can try wrapping your column with:

        Text.Upper(Text.Clean(Text.Trim([YourColumn])))

        This should standardize spaces, remove hidden characters, and align grouping with what you see in Excel.

        Let us know if that works out. Let us know if you have any doubts regarding this. We will be happy to help.

        Thank you for using the Microsoft Fabric Community Forum.