![]() ![]() The _ means the input table, and the SalesOrderNumber is the column that we want the unique values out of it, used inside the List.Distinct, the result is now the distinct count Īs I mentioned before in my other Power Query articles, once you know your way to writing M scripts (even part of the script), then Sky is the limit for the data transformation in Power BI. This happens by replacing the: Table.Distinct(_) You can replace that line of code with below = Table.Group(#'Sorted Rows', )Īnd that will give you the distinct count for the SalesOrderNumber columns. The (_) input for the Table.Distinct is the input parameter from the group by action, which is the sub-table for each group. Table.Distinct is used inside the Table.RowCount function. It, however, uses the Table.Distinct function, which ends up with something like below: If you use the Count Distinct Rows in the group by The Power Query function for a list of distinct values of a column is List.Distinct, which you can use it as below: So the challenge is how to do Distinct Count for the SalesOrderNumber column when using Group By. You can see some examples of such a scenario in the below screenshot: and that cannot be achieved with a count of rows, because there might be multiple records even per one SalesOrderNumber because the OrderLine information is also in the table For example, I am interested to know how many unique SalesOrderNumbers I have for each customer. What is usually more useful is the distinct count of a specific column. It might be only different if you really have a duplicate row with all columns having exactly the same value. This operation is most likely to return the same result as the Count Rows. The option that you see in the operations is Count Distinct Rows, which means for all columns except the Group By Column ![]() The limitation that I want to point out here is the DistinctCount. I previously wrote about a scenario that you can use to get the FIRST or LAST item in the group. The list of operations in the Group By aggregation, also useful, but it is limited. The Limitation of Distinct Count in Group By You can use Group By on a table like below on the CustomerKey (this table has multiple records per each CustomerKey) Īnd the result then would be a table with one CustomerKey per row īesides the Group by field, you can also have aggregated results from the other parts of the table, which can be determined in the Group By Configuration window Group By is a transformation which groups the result based on one or more fields, and provide an aggregated result from the existing table.Ĭonsider the table below, which is the FactInternetSales table. this table has multiple records per each CustomerKey To learn more about when to choose M (Power Query), or when to choose DAX for a calculation, read my article here. If the dynamic calculation is not part of the requirement, then Power Query can be a good consideration for the implementation. ![]() However, sometimes this calculation can be done as a pre-calculation, and only the aggregated result is what needed at the end, the details are not needed. Having a distinct count in Power BI using DAX is great. Why Power Query Transformation?īefore we start, it is important to know why in some scenarios, you might consider using Power Query for a transformation such as Distinct Count. In this article, I’ll show you a method you can use to get the distinct count of a particular column through the Group By transformation in Power Query component of Power BI. If you are doing the distinct count in Power Query as part of a group by operation, however, the existing distinct count is for all columns in the table, not for a particular column. You can have a distinct count calculation in multiple places in Power BI, through DAX code, using the Visual’s aggregation on a field, or even in Power Query. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |