Hi, Is there a way to build a power BI bar chart using multiple heirarchies and avoid calculating averages of averages when drilling up? - powerbi

I have a dataset with columns Country, State, City, Sales. I wanted to build a drill down bar chart to drill from country to State and then City, showing the average sales. My problem is that I can't find a workaround to avoid power bi calculating the average as the average of the inmediate lower heirarchy. Since I have States with much more cities than others, when I get to category Countries, the averages are wrong, because Two States with different amount of cities are weigthed the same way when summarizing to the upper level.
Is there any way to define the granularity level on which averages should be calculated or any other workaround.
Example
example dataset
For country A, I want to show the average as 16.
Currently is doing the average between States X and Y, whose averages are 17.2 and 13, giving 15.1 as a result.
Any help on how to solve this problem will be preciated. Thanks.

avgMeasure:= CALCULATE(AVERAGE(tbl[sales]),ALLEXCEPT(tbl,tbl[country]))

Related

Power Bi calculations

I am beginner with power BI and facing a little problem.
Actually I am working with a covid dataset. In one of the chart, I have to plot p-scores based on different age ranges over the years 2020-2022. When I put for example p-score of age range 15-65 on y axis, it gives me count of that where I just want to see the distribution of p-scores with no calculation.
Any solution would be highly appreciated. enter image description here

How to display a card with 90th percentile in PowerBI

I am new to PowerBI, and am trying to use a card to display three statistics: average, medium and 90th percentile. I understand how to create a card for average, and a card for medium.
How do I create a card for 90th percentile? There is no build in function 90th percentile. I can only see sum, average, minimum, maximum, count(distinct), count, standard deviation, variance, and median option.
You'll need to create a measure, and not use the built in aggregation functions of Power BI visuals. You can use the PERCENTILE.INC function, that will find the percentile over a column. Your measure will be:
Percentile of whatever = PERCENTILE.INC('tablename'[columnname], 0.9)
You should not use columns and then use visual aggregation type in Power BI, these are called 'naked measures' it is always best to create a measure, as you can reuse them in other visuals and the Power BI engine will calculate a bit quicker.

Power BI - Detect Outliers and the best way to show it

I have my data like this,
Country Value
USA 100
USA 120
USA 200
UK 200
UK 210
UK 400
I need to detect outliers for each country and show them in a visual.
I tried using the box plots (Country Vs Value), but I have nearly around 3M rows and it crashes. Any suggestions on how to solve this issue in a better way would be appreciated.
Power BI has anomaly detection since the November 2020 update.
If it's choking on the size of the data, then it might help to define an aggregated table where you group it at the level needed for the visual so that, e.g., you only have as many rows as countries for your example.
In case your data per country has a normal distribution. It may help to filter on the rows where the value column Z-score is higher than 3 times the Average of the data for country(i).
The Z-score measures how many standard deviations the data point is away from its mean (X̄). Then once identified the outliers for each country, you may draw a scatter plot, showing data points in the same plot, with a different color by country.

Can we do conditional formatting in Power BI using DAX?

I have a KPI which I need to conditional format based on a dynamic condition.
Example:
KPI : A
if A > Average of A in that cluster(A column present in the table) then the cell should be RED
if A lies between some values then the cell should be AMBER
if A lies below some value then the cell should be GREEN
I was doing conditional formatting by RULES prior to this but I cant seem to find an option there which can dynamically calculate the Average cluster total or Average country total and format the cells with colours.
Even if I make this DAX expression how do I put it in the table?
Also, is it even possible by DAX?

Get correct value in column sub total

In Power BI I am working with a matrix that shows a daily percentage.
When I add a column subtotal this sub total is summing up all the percentages for the selected days.
What I would like is that the Column sub total is showing the average percentage over the selected days.
Picture of the matrix
Thanks a lot for looking at my issue
Depends on how you calculate the percentage itself and on what granularity it exists in your data model, but you might want to play around with the ISFILTERED formula. Not sure what the name of the dimension ranging between 1 and 6 is in your graph, but let's call it day number. You can then do something like:
IF(ISFILTERED(day number), SUM(daily percentage), AVERAGE(daily percentage))
This checks if the daily percentage is filtered by the day number in the visual (matrix) or not. If it is, then it just takes the sum of the percentage (which is the percentage itself for any given day), otherwise it'll calculate the average percentage.