Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

DAX function for group by.. count

Hello, Need your help!

 

I am writing the following DAX

 

Measure = SUMMARIZE(CrimeDataAnalysisParsed,CrimeDataAnalysisParsed[State],CrimeDataAnalysisParsed[LocalDescription],"MostCrimes",count(CrimeDataAnalysisParsed[ID]))

but it says "the expression refers to multiple columns"

 

Basically I need to write dax for following sql query

 

select case BeatName
       when 'Beat 1' then 'Texas'
    when 'Beat 2' then 'Illinois'
    when 'Beat 3' then 'Kansas'
    when 'Beat 4' then 'Colorado'
    when 'Beat 5' then 'California'
    when 'Beat 6' then 'Minnesota'
    when 'Beat 7' then 'Ohio'
    when 'Beat 8' then 'Utah'
    when 'Beat 9' then 'Wisconsin'
    else BeatName end state,
  LocalDescription, (count(id)) cnt
from   CrimeDataAnalysisParsed
where  BeatName is not null
group  by BeatName,LocalDescription

 

I want to get a count of ID by grouping state and localdescriptio.

 

Please advise.

 

Thanks!

1 ACCEPTED SOLUTION
v-huizhn-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

SUMMARIZE returns a table rather than value, if you want to use SUMMARIZE fucntion. You need to click "New Table"->under Modeling on Home page, then type the following formula.

NewTable =
SUMMARIZE (
CrimeDataAnalysisParsed,
CrimeDataAnalysisParsed[State],
CrimeDataAnalysisParsed[LocalDescription],
"MostCrimes", COUNT ( CrimeDataAnalysisParsed[ID] )
)


Otherwise, if you want to create a measure, please use the following formula, then create a table visual, select CrimeDataAnalysisParsed[State],CrimeDataAnalysisParsed[LocalDescription] and measure as values level to display the result.

measure =
CALCULATE (
    COUNT ( CrimeDataAnalysisParsed[ID] ),
    ALLEXCEPT (
        CrimeDataAnalysisParsed,
        CrimeDataAnalysisParsed[State],
        CrimeDataAnalysisParsed[LocalDescription]
    )
)


Please feel free to ask if you have any other issues.

Best Regards,
Angelia

View solution in original post

4 REPLIES 4
fduran
Advocate I
Advocate I

Thank you Angelina! This is exactly what I needed to summarize my data in a stats table!

v-huizhn-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

SUMMARIZE returns a table rather than value, if you want to use SUMMARIZE fucntion. You need to click "New Table"->under Modeling on Home page, then type the following formula.

NewTable =
SUMMARIZE (
CrimeDataAnalysisParsed,
CrimeDataAnalysisParsed[State],
CrimeDataAnalysisParsed[LocalDescription],
"MostCrimes", COUNT ( CrimeDataAnalysisParsed[ID] )
)


Otherwise, if you want to create a measure, please use the following formula, then create a table visual, select CrimeDataAnalysisParsed[State],CrimeDataAnalysisParsed[LocalDescription] and measure as values level to display the result.

measure =
CALCULATE (
    COUNT ( CrimeDataAnalysisParsed[ID] ),
    ALLEXCEPT (
        CrimeDataAnalysisParsed,
        CrimeDataAnalysisParsed[State],
        CrimeDataAnalysisParsed[LocalDescription]
    )
)


Please feel free to ask if you have any other issues.

Best Regards,
Angelia

Very helpful Angelia

Anonymous
Not applicable

@v-huizhn-msft thank you so much! This is what I am looking for.

 

Thanks!

Harshad

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.