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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Pedro_Martínez
Regular Visitor

Calculate crime rates in Power BI

Dear PBI Community,

 

I'm pretty now to Power BI and I'm trying to calculate the crime rate per 100.000 inhabitants per municipality. I have a table with more than 100k rows, each one corresponding to a singular crime.

 

AñoHorarioCod_DepartamentoCod_MunicipioCod_ZonaSexoEdadCod_delitoGrupo_delitoÍndice
201611101121566931
201616602991426932
201612204991386933
201621105991696934
20163110161276935
201621108991397536
201621108991397537
201621108991397538
201615511991257539
2016255069913669310
201641111019912775311
201621313189914475312
201621414019912372313
2016144099915175314
2016311069913069315

 

In addition, I have established a relationship with another table with the code of each municipality and a column for the population of each one. Cod_Municipio are the columns related.

 

Cod_MunicipioPoblación
10138103
1021711
1031329
10488
105971
1061430
1071164
1089788
109244
1102132

 

So I need the rate per 100k inhabitants of each particular type of crime -categorized with numers from 1 to 7 in the Grupo_Delito column- and each municipality (Cod_Municipio). The idea is that after the measure, the visuals interact with other variables like age or sex.

 

I would appreciate very much your help.

 

Kind regards!

1 ACCEPTED SOLUTION
rohit_singh
Solution Sage
Solution Sage

Hi @Pedro_Martínez ,

Please try this : 

1) Using the relationship between the two tables, add a column on the crime rates table to show the population

rohit_singh_0-1653555052815.png

Pop = RELATED(Population[Población])
 
2) Create a measure to compute crime rate
rohit_singh_1-1653555118989.png

 

Crime Rate / 100k =

var _crimes = countrows(CrimeRates)
var _pop = max(CrimeRates[Pop])
var _crime100k = DIVIDE(_crimes,_pop,0) * 100000

RETURN
IF (ISBLANK(_crime100k), BLANK(), _crime100k)
 
3) This is the final result
rohit_singh_2-1653555199306.png

 

Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 🙂

View solution in original post

2 REPLIES 2
daXtreme
Solution Sage
Solution Sage

// Such a measure should work for
// any slicing and dicing.
// Here's the correct code:

[Rate Per 100K] =
// First, get the number of crimes in
// the current context. 'Crimes Statistics'
// is the fact table with individual crimes.
var CrimeCount = COUNTROWS( 'Crimes Statistics' )
// Then, you've got to sum up the populations
// from the Population table for all the cities
// that are visible in the current context. I assume
// that when you're slicing by city, it's done
// through the Population table. it is important
// to always slice by dimensions, never by the raw
// fact table's columns.
var TotalPopulation = SUM( Population[Población] )
var RatePer100K = 
    DIVIDE(
        CrimeCount * POWER(10, 5),
        TotalPopulation
    )
return
    RatePer100K

// This measure correctly responds to any slicing
// and dicing.
rohit_singh
Solution Sage
Solution Sage

Hi @Pedro_Martínez ,

Please try this : 

1) Using the relationship between the two tables, add a column on the crime rates table to show the population

rohit_singh_0-1653555052815.png

Pop = RELATED(Population[Población])
 
2) Create a measure to compute crime rate
rohit_singh_1-1653555118989.png

 

Crime Rate / 100k =

var _crimes = countrows(CrimeRates)
var _pop = max(CrimeRates[Pop])
var _crime100k = DIVIDE(_crimes,_pop,0) * 100000

RETURN
IF (ISBLANK(_crime100k), BLANK(), _crime100k)
 
3) This is the final result
rohit_singh_2-1653555199306.png

 

Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 🙂

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors