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

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.

Related

Calculate remaining amount available to invest in power BI

I am trying to create a table in Power BI that shows the remaining amount available to invest based on a 10% limit of total investments.
So for example, if we have 1,000,000 invested in 10 names, no name is allowed to be invested more than $100,000. What it looks like in excel is in the below image. it sumifs all the amounts that have days remaining >0 and then multiplies that amount by 10% to give us our 10% limit. It then sumifs each individual investment name for the total amount invested (A has 51,000,000 invested) and in the "remaining max allowed" subtracts that number from the 70,647,200 to show us how much more we can invest in that name
So far I have Created a measure that looks like this that gives me the amount invested with days remaining greater than 0, but I do not know how to then substract that number from 10% of the total amount of names invested with days remaining greater than 0
This was a lot of words, so I hope what I'm asking makes sense. Thanks

(SOLVED using VLOOKUP) Tiered/Nested IF clauses within one cell

Imagine a tiered revenue sharing scheme like this:
Revenue up to 10000 get 100% of it.
Revenue up to 12000 get the above plus 80% of the amount above 10000.
Revenue up to 14000 get the above plus 60% of the amount above 12000.
Revenue up to 16000 get the above plus 40% of the amount above 14000.
Revenue over 16000 get the above plus 20% of the amount above 16000.
E.g. A revenue of 13000 will get you a share of 10000+0.82000+0.61000 = 12200.
I tried making a table (each threshold a column) and calculate the individual fractions using IF clauses and then add them all up. It is very cumbersome. I would like to use only two cells with the entire calculation done in one cell, hard-coded.
If at all possible, extra bonus points if I can have the threshold values (10000, 12000, etc) and fractions (100%, 80%, etc.) in separate cells as parameters for the calculation, maybe something like an array-function?
Thank you very much in advance!
Start your lookup table with a value of 0 and a rate of 100%. In this case, VLOOKUP() with the last parameter equal to 1 will correctly find the required row.
In order not to recalculate all the above rows for each of the values, calculate them in advance and place them in the table as an additional column.
For the first line it will be 0, and calculate all subsequent values using a formula like =C2+(A3-A2)*B2
For such a table, a not very complicated formula will return the correct result:
=(<revenue>-VLOOKUP(<revenue>;<lookup_table>;1;1))*VLOOKUP(<revenue>;<lookup_table>;2;1)+VLOOKUP(<revenue>;<lookup_table>;3;1)
The third parameter in the VLOOKUP() functions increases from left to right: 1 - the base amount, 2 - the interest rate, 3 - the calculated markup for reaching the previous levels.
For the data shown in the figure, the formula is used
=(E2-VLOOKUP(E2;$A$2:$C$7;1;1))*VLOOKUP(E2;$A$2:$C$7;2;1)+VLOOKUP(E2;$A$2:$C7;3;1)

DAX TOPN Filter Not Returning Enough Rows

I'm trying to apply a TOPN() visual filter to a Power BI sheet based on an Average Loan Amount measure. I want to see the top 5 employees with the highest average loan amount, ignoring employees who have disbursed 4 or fewer loans.
The problem I'm running into is that I don't get 5 rows returned, even though I've selected the top 5. I have to adjust the "TOPN" parameter (in the visuals) to include more than 5, just to get 5 rows.
This seems to be because when I have both the TOP5 average AND the loan count > 4 filters working, neither updates the other; that is, I can find the top 5 rows based on the average parameter, but once I include the "loan count > 4" condition, a few of the top 5 disappear, and they're not replaced by the runners-up to the original 5.
In the past, when I placed a top 5 filter for average and nothing came up, it was because all the top 5 entries all had a loan count of under 5. Once I relaxed the "TOPN" condition to be "TOP 52," I got 5 entries visible.
Does anyone know why this happens & how to fix it so I always get 5 rows returned?
EDITED TO ADD: For an example of the data, please click here. Please note that any employee with a loan count of 4 or less should be filtered out. I created the filter in PowerBI because the data sets are dynamic, and so are the filter results.
The fundamental problem is that you're applying 2 filters to the same visualization:
You only want to include employee's with a loan count of 5 or more
Of those, you want the 5 employees with the highest average loan amount
Power BI is applying both filters independently. So, it is taking the 5 employees with the highest average loan amount, and then removing 3 of them because their loan count is less than 5. I can imagine this is a common problem for people working with a Top N filter plus another filter.
One way to work around this (and I don't claim this is the only or even the best way), is to take into account the loan count before calculating the average.
For example, assuming you have the following two measures and the following data:
Loan Count = DISTINCTCOUNT(Employee[Loan Number])
Avg Loan Amt = AVERAGE(Employee[Loan Amount])
It's clear from the picture that Liz, Montgomery and Oscar are in the top 5 but have only 3 loans to their name.
Next, we can create a new measure that checks the Loan Count before calculating the average loan amount. If the loan count doesn't meet the threshold, you don't care about their average.
*Filtered Avg Loan Amt = IF([Loan Count] < 5, BLANK(), [Avg Loan Amt])
This creates the following result. Notice that Liz, Montgomery & Oscar now all have no average calculated because they don't have enough loans.
Now, you don't necessarily have to display the Filtered Avg Loan Amt measure on your table, but you can now use that measure in your Top N visual filter and that, by itself, will filter your table to the top 5 employees with a high enough loan count.
Notice that in my filters, I only have 1 filter (on Filtered Avg Loan Amt). I don't also need to filter to a loan count of 5 or greater. This results in the following top 5 employees:
I hope this solves the problem you're having!
Unrelated sidenote: if you're using this threshold of 5 in a few places, I would recommend sourcing the number from an external source (including possibly a disconnected table) rather than hard-coding 5 in the measure itself. That way, if someone decides that 5 isn't the right threshold, you only have to update it one place, rather than hunting through all your measures looking for the number 5. There's an article here on using a disconnected table so that end-users can pick the threshold themselves (though it could definitely be overkill for your situation): https://powerpivotpro.com/2013/08/moving-averages-controlled-by-slicer/

Average Power BI Aggregates

I have entries that are uniquely identified by a variety of fields and that I pull in from Excel. Entries relate to the daily amount of work done, and people working on a specific area of a plant. Each entry has a work done field (measurement of the work done on that area), and a manpower count. The productivity per area is calculated by work done divided by manpower.
Date Area Work Done Manpower Productivity
2017/02/01 Pipe 50 25 2
2017/02/01 Valve 22 2 11
2017/02/01 Machine 54 2 22
I want to display the work done and manpower as bars in power BI, and the average productivity per day as a line. The problem is that the real productivity for the day (total work done divided by total manpower) is not the average of the individual productivity per area. Thus, I want to be able to create a line that total work done and manpower per day, and divides them to get the productivity, then only displays the productivity.
How can I do this in power BI?

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

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.