statisticsdax# DAX statistics calculation

The problem is solved! Sam Nseir has found a solution!

[I am currently analyzing a survey (approx.60.0000 respondents in 30 European countries) on the topic of xenophobia. More precisely: how many women and men in each country (in % of the sample) are xenophobic.

Ive checked a bit of this data by Czech Republic (CZ in the table - out of 2476 respondents from CZ 574 have answered xenophobic questions (3 times NO to migrants, i.e. 4-4-4 in the answers (column names [impcntr], [imsmetn], [imdfetn])) -and these are 259 men and 315 women (i.e. of all respondents in the Czech Republic, so 10.46% and 12.72% female out if 2476). This is exactly what I need for each country in Europe (the percentages).

Also --the gender is mentioned as -1 male and 2-female from the [gndr] column.

I’ve made these formulas in the first place:

```
MeasureMale= CALCULATE(COUNTAX('male-female xenophobes','male-female xenophobes'[gndr]), 'male-female xenophobes'[gndr]="1" && 'male-female xenophobes'[impcntr]=4 && 'male-female xenophobes'[imsmetn]=4 && 'male-female xenophobes'[imdfetn]=4)
MeasureFemale = CALCULATE(COUNTAX('male-female xenophobes','male-female xenophobes'[gndr]), 'male-female xenophobes'[gndr]="2" && 'male-female xenophobes'[impcntr]=4 && 'male-female xenophobes'[imsmetn]=4 && 'male-female xenophobes'[imdfetn]=4)
```

Then I’ve made some New Measures to calculate a percentage: how many men out of each country are xenophobic and how many women (in % out of samples per country).

```
percentage xenM per country = 100*divide([MeasureMale], COUNTROWS(ALLNOBLANKROW('male-female xenophobes')))
percentage xenF per country = 100*divide([MeasureFemale], COUNTROWS(ALLNOBLANKROW('male-female xenophobes')))
```

However, the resulting graph seems incorrect.. what could be the reason, maybe someone can advise??

Further I need to calculate how many man and women (in %) out of Entire EU sample from my datasheet (approx.60.000) is xenophobic. Could anyone help me here?

Thank you a lot in advance!!

Solution

I think I have spotted two issues:

- Your are multiplying your percentage by 100 (you shouldn't)
`ALLNONBLANKROW`

returns the whole table ie 60,000

Put these together, and it could explain your chart. For example:

- 259 CZ men out of 60,000 = 0.0043
- your a multiplying that by 100 = 0.43
- and most likely you have the measure formatted to Percentage = 43%

43% looks pretty close to what you have on your chart for CZ Male.

Try the following (these are all measures):

```
Respondent Count = COUNT('male-female xenophobes'[idno])
MeasureMale= CALCULATE(
[Respondent Count],
'male-female xenophobes'[gndr] = "1" &&
'male-female xenophobes'[impcntr] = 4 &&
'male-female xenophobes'[imsmetn] = 4 &&
'male-female xenophobes'[imdfetn] = 4
)
MeasureFemale = CALCULATE(
[Respondent Count],
'male-female xenophobes'[gndr] = "2" &&
'male-female xenophobes'[impcntr] = 4 &&
'male-female xenophobes'[imsmetn] = 4 &&
'male-female xenophobes'[imdfetn] = 4
)
percentage xenM = DIVIDE( [MeasureMale], [Respondent Count])
percentage xenF = DIVIDE( [MeasureFemale], [Respondent Count])
percentage xenM of All = DIVIDE(
[MeasureMale],
CALCULATE( [Respondent Count], ALL('male-female xenophobes') )
)
percentage xenF of All = DIVIDE(
[MeasureFemale],
CALCULATE( [Respondent Count], ALL('male-female xenophobes') )
)
```

- Evaluating integral using Riemann sums
- Difference between automated stat_summary statistics and standard error by hand
- How do I do a F-test in python
- median(x) is does not correctly return the middle value of x
- Simple statistics - Java packages for calculating mean, standard deviation, etc
- How do I calculate r-squared using Python and Numpy?
- Quantile-Quantile Plot using SciPy
- Building a 6/49 Lotto Ticket Simulation
- I am trying to make a simple program to go through survey data for a project at school, but it is not working
- Computing multivariate normal in scipy
- What is an efficient way to generate 10000 samples for 16 sets of parameters in R?
- 1D kernel estimation to compare PDF ratios: how to set tails?
- Is there a way to reuse a glm fit, if all I have is the model fit call and summary?
- Find percentile stats of a given column
- regression model for toxic elements and epigenetic age
- .NET numerical libraries
- Post-Hoc tests for chi-sq in R
- How to add summary statistics next to a legend in ggplot2?
- How to add legends in ggplot for a curve that derive from another df?
- Querying database with eloquent to get a sum of values for statistics charts
- How to plot 1D array using python to get 25th, 50th and 75th percentiles
- Looking for a Histogram Binning algorithm for decimal data
- How does convolution work in stats::filter
- Struggling to remove values from one vector using another larger vector iteratively in R (sample.int invalid first argument error)
- How to calculate variance explained by a variable of interest, in a lm model with covariates?
- Newey-West standard errors for OLS in Python?
- Data is normally distributed, but ks test return a statistic of 1.0
- Is there a simplified SQL query to return the number and percentage of missing values of a table ? (BigQuery)
- Statistically removing erroneous values
- How to replace dataframe values based on index statistics