Marketing penetration in OLAP cube - Help with specific MDX measure definition - sas

I am pretty new to MDX but I know what I want accomplish but its proving very hard. Basically, I have a dataset where each row is a sale for a customer. I also have postcode data and the UK population at each ward.
The total population in each ward is then divided by the count of the wardcode within the data set - e.g. ward A had a population of 1,000. I have ten customers who live in ward A and so the population value is therefore 1,000/10.
So as long as there are no other dimensions selected, only the region hierarchy, I can then drill up and down and the population penetration as count of customers / calculated population value is correct. However, as soon as I introduce more dimension the total population will not sum to its true value.
So I therefore need to do the calculation above within the cube and I am trying to find the MDX function(s) to do this.
Esentially something like -
step 1) sum the number of ward codes (the lowest level of the Geographic hierarchy) and group this by the distinct ward code, eg wardcodeA = 5, wardcodeB=10 etc.
Step 2) Then take the population in each ward (which could be stored as the total at ward level and taking the average) and then divide this by the result of the previous step
step 3) sum the results from each ward at the currently select Geographical level

The fact other dimensions are changing the value of customers / population means that something in your modeling is wrong.
You should have a fact table (can be a view/concept) like this :
REGION_ID, CUSTOMER_COUNT, POPULATION_COUNT
Once you got this create a fact table and a specific measure for counting customers and population with a single dimension linked. This is the main point, do not link your measures with dimension that are not needed.

Related

Power BI: Categorize customers based on measures

I have a list of customers that I wish to categorize based on two criteria: Share of total income and average time from due date to payment date.
I have a table with customer transactions that I can use to calculate these two criteria.
The solution I currently have is to use calculated columns in the customer table:
Sum of invoiced amount per customer/Total sum all customers = Share of total income
Average number of days per customer
I then use IF-functions to categorize these metrics into Big/Medium/Small customers, and Good/Medium/Bad payers.
Next I use a Matrix visualization to see number of customers for each category (Big customer/Good payer, Small Customer/Medium payer, and so on).
The problem I get is that the outcome of this is static, and they doesn't change if I use slicers to get only transactions from one year, or for only one of our companies.
Can I instead use measures for this, and get a dynamic Matrix visualization?
You need to use measures for this. It is a common pattern known as dynamic segmentation. You can read how to implement it here: https://www.daxpatterns.com/dynamic-segmentation/

Creating a measure for specific requirement in Power Bi

I am facing this below issue.
I need to calculate Budget variance % which is ((Actual Cost -Budget)/Budget)*100. So for that we need to sum the actual cost for a particular month say, January,2021 and have to subtract budget for that particular month(Jan) only, for each costcenter , and we have got only single budget for every month for each cost center whereas we have actual cost for each day in a month ,for each cost center ,which will be summed up. Actual cost and budget are coming from 2 diff tables say A & B respectively. Table A is having columns named Cost center,Date,ActualCost,OrderID. Table B consists of columns named, Cost center,Date,Budget. Date column is having diff set of dates in two diff tables A & B. So, when I am trying to do the required calculation, its throwing error . Can anyone please help me with the steps to follow to calculate this Budget variance?

Count number of records totalling a given percentage of the overall total in Power BI

I'm relatively new to power bi so please bear with me!
I have a report which looks at information about individual stores of a given customer.
One of the requirements is to show the % that the top N stores constitute to the overall total, for example the top 1 store makes up 30% of overall sales, top 5 stores make up 65% of the overall total, etc. I can achieve this easily using the 'Top N' filter function.
The other requirement is to count the number of stores which total 80% of the overall total sales. For example, we have a total of 100 stores for a given account which generate a revenue of £10,000. The top 60 stores generate a revenue of £8,000, therefore 60 of the 100 stores make up 80% of the overall sales.
Hopefully that makes sense! Is this possible within power bi? If so could someone point me in the right direction?
Thanks in advance for your help.

Measure to sum another aggregated measure's data

I am working on a report that has data by month. I have created a measure that will calculate a cost per unit which divides the sum of dollars by the sum of production volume for the selected month(s):
Wtd Avg = SUM('GLData - Excel'[Amount])/SUM('GLData - Excel'[Production])
This works well and gives me the weighted average that I need per report category regardless of if I have one or multiple months selected. This actual and budget data is displayed below:
If you take time to total the actual costs you get $3.180. Where I am running into trouble is a measure to sum up to that total for a visual (This visual does not total sadly). Basically I need to sum the aggregated values that we see above. If I use the Wtd Avg measure I get the average for the total data set, or .53. I have attempted another measure, but am not coming up with the correct answer:
Total Per Unit Cost = sumX('GLData - Excel','GLData - Excel'[Wtd Avg])/DISTINCTCOUNT('GLData - Excel'[Date])
We see here I return $3.186. It is close, but it is not aggregating the right way to get exactly the $3.180:
My Total Per Unit Cost formula is off. Really I am simply interested in a measure to sum the post aggregated Wtd Avg measure we see in the first graph and total to $3.180 in this example.
Here is my data table:
As you probably know already, this is happening because measures are dynamic - if you are not grouping by a dimension, they will compute based on the overall table. What you want to do is to force a grouping on your categories, and then compute the sum of the measure for each category.
There are 2 ways to do this. One way is to create a new table in Power BI (Modeling tab -> New Table), and then use a SUMMARIZE() calculation similar to this one to define that table:
SUMMARIZE('GLData - Excel',[Category],[Month],[Actual/Budget],"Wtd Avg",[Wtd Avg])
Unfortunately I do not know your exact column names, so you will need to adjust this calculation to your context. Once your new table is created, you can use the values from that table to create your aggregate visual - in order to get the slicers to work, you may need to join this new table to your original table through the "Manage Relationships" option.
The second way to do this is via the same calculation, but without having to create a new table. This may be less of a hassle. Create a measure like this:
SUMX(SUMMARIZE('GLData - Excel',[Category],[Month],[Actual/Budget],"Wtd Avg",[Wtd Avg]),[Wtd Avg])
If this does not solve your issue, go ahead and show me a screenshot of your table and I may be able to help further.

COUNT the number of times a DAX measure is > X

New to DAX.
I have a rather (from my point of view) complicated tables relationship model :
Model
It's a knowledge database in my company.
There are many "compétences" for each employee in table DONNEES. These "compétences" are categorized in the LMC table which is a bridge table between COMP & METIERS defining the "compétences" needed for a "métier".
One "competence" can be in multiple "métiers"
In table "DONNEES" I have all employees, plus standards profils for each "métier". This table defines the level (1 to 5) for each "competences".
My matrix in Power Bi works like a charm. I can sum all "competences level" for each métiers.
I've added a measure, which normalizes this sum over the sum gotten for each standard profil (this sum is "hard coded" in METIERS, not calulated)
Grade = CALCULATE(SUM(DONNEES[Niveau]); LMC)/CALCULATE(SUM(METIERS[Niveau_type]);LMC)*5
And it works (even if the "total" columnn isn't correct)
//EDIT//
With the following modifications, it works :
Grade = CALCULATE(SUM(DONNEES[Niveau]); LMC,DONNEES,METIERS)/CALCULATE(SUM(METIERS[Niveau_type]);LMC,DONNEES,METIERS)*5
(I've added all tables from my many to many relationship)
The grand total column is now ok.
//EDIT//
Now, I want to compute a the number of employee that fulffil a specific grade for each métier.
I've thought to create a binary measure that checks that :
gradefulfilled= IF(DONNEES[Grade]>4,5;1;0)
An then use the total row to have the number of employees in the company able to do that "métier"
It doesn't work. The total sticks to zero, even if the gradefulfilled binary is correct for everyone.
//EDIT//
The total does'nt stick to zero, it can be 1 if there's one employee OK, but sticks to 1 if more than one employee.
//EDIT//
You can propose either a totally different way to compute what I want (number of employees able to do a "métier" or explain to me where I made a mistake in my computations.
Hurray !
My bad. Problem seems solved.
The problem seems related to the way grand total is calculated in pivot table (the sum of the measure calulated for each line, not on the sum of each measure in the matrix)
So I've used a sumx to get a proper sum :
Nbgradefulfilled = sumX(NOMS;DONNEES[gradefulfilled])