Forum Discussion

refint650's avatar
refint650
Icon for Helper III rankHelper III
4 years ago
Solved

SQL Group b to Dax measure for row count

Hello

how to translate this sql group by condition to dax measure to find distinct employee count based on selected value from slicers

select distinct id, name, date, location, count(1) from table a. group by  id, name, date, location

 

Thanks

Vs

2 Replies

  • you get that for free in Power BI.  It automatically aggregates/groups.

     

    Please provide sanitized sample data that fully covers your issue. I can only help you with meaningful sample data.
    Please paste the data into a table in your post or use one of the file services like OneDrive or Google Drive. Screenshots of your source data are not useful.
    Please show the expected outcome based on the sample data you provided. Screenshots of the expected outcome are ok.

    https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
    https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

  • This measure worked for calculating the distinct row count for a group by statement

     

    RowCount =

    VAR table1 =

        CALCULATETABLE (

            Employee,

            DISTINCT (

                SELECTCOLUMNS (

                    Employee,

                    "ID", Employee[ID],

                    "Name", Employee[Name],

                    "Date", Employee[Date]

                )

            )

        )

    RETURN

        CALCULATE (

            DISTINCTCOUNT ( Employee[ID] ),

            FILTER ( table1, Employee = 'USA' )

        )

     

    or

     

    var emp = group by ( table, column1, column2, column 3 )

    return calculate (distinctcount(id),  filter(emp, filter condition column expression)