Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.
Hi!
I have two columns in a table. State and PersonsName. I want to calculate the count of distinct states that contain more than 10 distinct PersonsName.
Almost like how a GROUP BY in SQL would work.
Any ideas on how to accomplish this?
Thank you!
Hi,
I made a PBI with diffrent options for your questions.
I made a table with 2 columns (States and PersonName) and gave you 5 options :
1/ In Power Query by making a Group By. Good option if you don't need you data in details. See my first query for that option.
2/ Using DAX, you can make a basic calculation but your totals will be wrong, because of the lack of filter context on totals.
NbPersonDAX_Mesure = DISTINCTCOUNT(TableStatesPersonDAX[PersonName])
NbPersonDAX_Mesure v2 =
VAR CurrState=SELECTEDVALUE(TableStatesPersonDAX[States])
RETURN
CALCULATE(
DISTINCTCOUNT(TableStatesPersonDAX[PersonName]),
TableStatesPersonDAX[States]=CurrState)
NbPersonDAX_Mesure v3 = SUMX( VALUES(TableStatesPersonDAX[States]) ,
CALCULATE( DISTINCTCOUNT( TableStatesPersonDAX[PersonName] ) ) )
TableDAX_withFILTER = FILTER( SUMMARIZECOLUMNS(TableStatesPersonDAX[States], "NbPersonStates" ,
DISTINCTCOUNT(TableStatesPersonDAX[PersonName])) ,[NbPersonStates]>2 )
You can use DAX formula to achieve this in Power BI. Here's an example measure that counts the distinct states that have more than 10 distinct PersonNames:
Here, we use the SUMMARIZE function to group the data by State and calculate the number of distinct PersonNames for each State. Then we use the FILTER function to include only those rows where the count of distinct PersonNames is greater than 10, and finally use the COUNTROWS function to count the number of distinct States that meet this condition.
Replace "Table1" with the name of your actual table and "State" and "PersonsName" with the names of your actual columns.
Check out the November 2023 Power BI update to learn about new features.
Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.