Percent of total from subgroups - Power BI - powerbi

I am new to Power BI and got stuck with the following problem:
For research purposes, I have some data about the participation of students of acourse (the example chart you can see is filtered by students not visiting the course.
The first barchart shows how many students visited those course, the second chart should show those values in percent, calculated from the subtotal.
So the value in percent of Bachelor in SS 15 should be 23,305% (total bachelor students in SS15 was 2533: 595 / 2533 * 100)
I am not able to get this values correctly calculated.
Thanks for your help!
EDIT
The Data is structured as followed:
Hash Semester Status Stg (...)
xxx1 SS 15 A Diplom
xxx2 WS 16/17 A Master
xxx1 SS 15 N Diplom
xxx1 SS 17 A Bachelor
xxx2 SS 15 N Bachelor
... ... ... ...
The hash is the identifier for the Student.
The data contains around 55.000 rows and is imported as an unstructured Excel-list. The chart is filtered by status.
Until now I dont use custom measures but the build in measures via drag and drop.
I got the percentage values by selecting "show value as percent from column total".

First, create these following 3 measures-
1.
hash_total = COUNT(your_table_name[Hash])
2.
hash_semester_total =
var cur_sem = MAX(your_table_name[Semester])
RETURN
CALCULATE(
COUNT(your_table_name[Hash]),
FILTER(
ALL(your_table_name),
your_table_name[Semester] = cur_sem
)
)
3.
hash_percentage = [hash_total]/[hash_semester_total]
Change the Type of measure "hash_percentage" as %
Now configure your clustered column chart as below-
The output will be as below-

Related

Active users on a given date in a Month in Power BI

I am working to get cumulative distinct count of uids on daily basis. My dataset consists dates and UserIDs active on that date. Example : Say there are 2 uids (235,2354) appeared on date 2022-01-01 and they also appeared on next day with new uid 125 (235,2354,125) on 2022-01-02 At this point i want store cumulative count to be 3 not 5 as (user id 235 and 2354 already appeared on past day ).
My Sample Data looks like as follows:
https://github.com/manish-tripathi/Datasets/blob/main/Sample%20Data.xlsx
enter image description here
and my output should look as follows:
enter image description here
Here's one way that seems to work, using your linked Excel sheet as the data source.
Create a new table:
Table 2 = DISTINCT('Table'[Date])
Add the columns:
MAU = CALCULATE(
DISTINCTCOUNT('Table'[User ID]),
'Table'[Date] <= EARLIER('Table 2'[Date]))
DAU = CALCULATE(DISTINCTCOUNT('Table'[User ID]),
'Table'[Date] = EARLIER('Table 2'[Date]))
Result from your Excel data

DAX measure to extract summed quantity values for selected weeks only

I have production figures which sum the quantity of parts produced by each workstation on a weekly basis. These are shown in a matrix with workstation number on the rows and week numbers across the columns.
I want to be able to select 2 weeks and then
Display all the weeks in the range selected by a slicer.
Show the quantity values for only the first and last selected weeks.
The first part is working using a simple Week Slicer.
The second part, however, always shows the totals for all the selected weeks rather than the 2 individual week quantities.
In this example I have selected weeks 4 and 9 and therefore the expected values for quantities are 11,505 and 49,425 as shown in the Good Qty data with red frames.
The measures to extract the fist and last selected week numbers are working:
SelWeek1 = FIRSTNONBLANK(VALUES(vLink[Week]),0)
SelWeek2 = LASTNONBLANK(VALUES(vLink[Week]),0)
My measures for the week quantities are:
IF([SelWeek1]>0,
CALCULATE([Sum vGood Qty],FILTER(vLink, vLink[Week] = [SelWeek1])),
0
)
and
SelWeek2 Qty =
IF([SelWeek2]>0,
CALCULATE([Sum vGood Qty],FILTER(vLink, vLink[Week] = [SelWeek2])),
0
)
What am I missing?
Try to use below measures:
SelWeek1 = MIN(vLink[week])
Measure =
VAR _selWeek = [SelWeek1]
VAR result =
CALCULATE(
[Sum vGood Qty],
vLink[Week] = _selWeek
)
RETURN
result
and for selected week 2 change min to max in the first measure and _selWeek variable in the second measure respectively.

How to create line chart in PowerBI when the value is a text (Ok, Incorrect)?

Hi everyone,
I want to plot the line chart above in PowerBI based on the data that I have in column A,B and C. The challenge that I have is that the Values of the line chart only able to show as Percent of grand total instead of Percent of row/column total.
I'm still new to PowerBI, not sure any new measure that I can use to create the line chart above.
The line chart above is what I'm able to create in PowerBI, may I know what should I do to change the y-axis into percentage (percentage of OK for Mar + percentage of Incorrect for Mar = 100%) ? Any help will be greatly appreciated!
First create these below 3 measure-
total_student = DISTINCTCOUNT(your_table_name[Name])
ok_% =
VAR OK_COUNT = COUNTROWS(
FILTER(
your_table_name,
your_table_name[Answer] = "ok"
)
)
RETURN (OK_COUNT/your_table_name[total_student])
incorrect_% =
VAR incorrect_count = COUNTROWS(
FILTER(
your_table_name,
your_table_name[Answer] = "incorrect"
)
)
RETURN (incorrect_count/your_table_name[total_student])
Now convert last 2 measure as % and create your chart. Here below I have created everything for first 2 month from your sample data-
Note Your Month field need proper ordering for correct output.

How to Calculate 3 Month Rolling Average with my current dataset in Power BI?

I'm new to power BI and i require your assistance. I want to create a visualisation showing the average number of tickets from the previous 3 months and compare it with the current month. Is there any easy way to do this?
I have tried many solutions online but it dosen't work. I think it is because my dataset may not suit the solution.
My data:
Tickets | Date
1 | 6/30/2019
1 | 6/10/2019
1 | 7/1/2019
0 | 7/2/2019
1 | 6/30/2019
There are many more columns and rows. The value of ticket is either 1 or 0 and the date can be repeated. This is the data i received from an API.
This is what i currently have
The data would get bigger and bigger as time goes by.
I would want to add a 3month rolling average line in this current visualization that i have.
Thank you!
Here we go:
First I created a column FirstDayMonth,this I use to group all data of the same month
FirstDayMonth = EOMONTH(Tickets[Date];-1)+1
My table looks like:
Next I create a summarized table grouped by the FirstDayMonth
TicketsMonth = SUMMARIZE(Tickets;Tickets[FirstDayMonth];"Amount"; SUM(Tickets[Tickets]))
I add a column Ave3PrevMonth
Ave3PrevMonth =
var totalMonths = YEAR(TicketsMonth[FirstDayMonth]) * 12 + MONTH(TicketsMonth[FirstDayMonth]) - 3
var periodStart = DATE(totalMonths/12;MOD(totalMonths;12);1)
var periodEnd = TicketsMonth[FirstDayMonth]
return
CALCULATE(SUM(TicketsMonth[Amount]);
FILTER(TicketsMonth; TicketsMonth[FirstDayMonth] >= periodStart && TicketsMonth[FirstDayMonth] < periodEnd))/3
This is the tricky bit as Power bi is not strong with dates..
I added an extra column PeriodStart to show the date from where average is taken:
PeriodStart =
var totalMonths = YEAR(TicketsMonth[FirstDayMonth]) * 12 + MONTH(TicketsMonth[FirstDayMonth]) - 3
return DATE(totalMonths/12;MOD(totalMonths;12);1)
End result:

Power BI: Top 5 clients Profit% chart wrong due to clients sharing multiple branches

I have a requirement to show Gross profit and GP% for the top 5 clients.
I have created the Gross profit bar chart for top 5 clients and its correct as expected. I have concatenated the client and branch columns in table Revenue and used that to get top 5 clients.
But for GP%, I have created the following measure.
% GP per Client = DIVIDE ( SUM ( Revenue[GrossProfit] ), CALCULATE ( SUM ( Revenue[GrossProfit]), ALL ( DimClient[ClientName]) ))
I am unable to filter with branch and client concatenated and so getting wrong values. Snapshot of sample data, wrong chart and required correct chart below:
Here is the relationship between my tables:
Can anyone please let me know how I can achieve the correct values in GP%?
Regards
Can you try below measure :
grossprofit total for clientid =
CALCULATE(SUM('revenue'[grossprofit]), ALLSELECTED('revenue'[clientid]),ALLSELECTED('revenue'[branchid]))
Note : change the Show Value as option to Percentage of Grand Total in Values toolbar options
I fixed my issue by creating the following measure.
% GP per Client = DIVIDE (
SUM ( revenue[GrossProfit] ),
CALCULATE ( SUM ( revenue[GrossProfit]), ALL (revenue[Client And Branch])
))
Apply the filter on [client and branch] column for top 5.
My Issue was I was selecting all clients from clients table, I should have been selecting all clients and branch combined from the revenue table itself.