I have a table named 'DIM_Employee_Details' which contains Employee details along with supervisor id. Each employee has a supervisor. I am applying RLS based on employee id such that when an employee logs in, only the details of the employees who are under the same supervisor are shown. I want to display the rank of employees in descending order under a supervisor based on a measure. Kindly check the below measure used for ranking:
KPI Rank By Supervisor = VAR __ID = MAX(DIM_Employee_details[Supervisor_ID])
RETURN CALCULATE(RANKX(
ALLSELECTED(DIM_Employee_details[emplid])
,([Overall_attainment]),,DESC,Dense),
ALLEXCEPT(DIM_Employee_details,DIM_Employee_details[Supervisor_ID],DIM_Employee_details[emplid]), DIM_Employee_details[Supervisor_ID] = __ID)
While applying this, I am getting the max rank for which overall attainment has values and 1 for which it has blank values.
emplid
Employee_Name
Supervisor_ID
SUPERVISOR_NAME
1
A
IN087263
Yash
2
B
IN087263
Yash
3
C
IN087263
Yash
4
D
IN087263
Yash
Related
I'll explain my problem with an example:
I have three tables: one of dates, another of employees and another of departments.
There are two relationships:
dim_date[date_id] -> dim_employee[start_date_id]).
dim_department[department_id -> dim_employee[current_department_id]
dim_employee
name
current_department_id
start_date_id
Employee 1
1
20210701
Employee 2
2
20210701
Employee 3
2
20210901
Employee 4
1
20220201
Employee 5
2
20220201
dim_department
department
department_id
Purchase department
1
Sales department
2
I want to count how many employees each department had, for example, in February 2022 (using a slicer).. I've tried this:
num_employees_purchase_department =
CALCULATE(
DISTINCTCOUNT(dim_employee[employee_id]),
dim_employee[current_department_id]=1
)
However, since the relation is made through start_date_id, I only get the new hires of each department (one for the sales department and one for the purchase department) and not the total number of hired personnel.
The result that I'm looking for:
Employees in Purchase Department: 2
Employees in Sales department: 3
Thank you so much!
Try to make dim_date - dim_employee relationship inactive (in Data model view) and add an extra condition into your measure:
CALCULATE(
DISTINCTCOUNT(dim_employee[name]),
dim_employee[start_date_id] <= MAX(dim_date[date_id])
)
Don`t forget to use USERELATIONSHIP() inside your other measures where active dim_date - dim_employee relationship is necessary.
I am trying to produce a cluster column chart with Month/Year as the x-axis and the number of enrolled and finished students within each month as y-axis, which would look like this (navy: enrolled students, red: finished students; A: April, B: May, etc):
In EXCEL, what I want to do would be simply put as:
Number of Enrolled = COUNTIFS('Student Enrolment Date', '>=01/04/2021', 'Student Enrolment Date', '<=01/04/2021')
Number of Completed = COUNTIFS('Student Finish Date', '>=01/04/2021', 'Student Finish Date', '<=01/04/2021')
Then use the calculated values to produce a visual.
The data example (let's call it Student) is as below:
I have also produced a date dimension as below:
I get confused about how to do this using DAX. If I connect Student['course start date'] with Date['Date'], and use Date['Year-Month'] as x-axis as below, then Power BI will count all students whose Student['course start date'] fall into each month. But because students is not necessarily get enrolled and finished in the same month, this method is apparently incorrect.
My questions are:
I am now trying to count the date in Student['student enrolment date'] and Student['student finish date'] within each month using:
Student Complete = COUNTROWS(FILTER(Student, Student[Status]="Complete" && Student[student enrolment date]>=DATE(2021, 4, 1) && Student[student enrolment date]<=DATE(2021, 4, 30) + 0))
but DAX says this is not a correct formula, and I don't know how to make this formula calculate for each month. Could you please correct me?
In my case, how to properly connect the date dimension to the Student dimension?
I think your model is not ok and that's why your DAX is much more complicated than necessary.
Create a fact table that connects your dimensions.
e.g. factStudentEvents
StudentId dateId Enrollments Completions
----------- ----------- ----------- -----------
1 20210413 1 0
1 20210620 0 1
2 20210427 1 0
Like this your DAX measures are very simple:
Completion Count = SUM(factStudentEvents[Completions])
Enrollment Count = SUM(factStudentEvents[Enrollments])
I have two models: Data and Product Master.
Their relationship is defined as joining by Category Name:
I have written measure as:
2. Total sales = SUM(Data[Sales Amount])
It appears as:
Then I checked:
It shows:
Why is not the distribution of category name and Name and showing in table?
Then after If , I uncheck measure 2. Total sales then it will show:
Why is the distribution of of category name and Name not showing according to total sales?
Check your relationship. Are you sure that you connect the correct columns? Data Type is that same? Any white space on one side of the relationship? "Tshirt " instead of "Tshirt"
I have 2 tables AW_Sales and AWProducts.
AW_Sales
OrderDate OrderNumber Orderquantity ProductKey
1-1-2019 SO1 2 P1
AWProducts
ProductKey ProductCost ProductPrice ProductName
P1 200 400 Product1
I am trying to create a new measure price in AW_sales table by trying to replicate product price from the table products.
Price = Related(AW_Products[ProductPrice])
Error:
The column 'AW_Products[ProductPrice]' either doesn't exist or doesn't have a relationship to any table available in the current context.
The relationship between sales and product table clearly exists
I want to get a distinct count of Enquiries with Food and Drink in Power Bi. The way the database is structured is:
1 Enquiry could have multiple days, which have food and drink attached to them.
I want to try and calculate how many enquiries have food and drink attached so I need to do a distinct count on the enquiry id in the Enquiries table where a record exists in the food and drink table
The table structure is as follows:
Enquiry Table
EnquiryId
10
Enquiry Day Table
EnquiryDayID EnquiryId
5 10
6 10
Enquiry Day Food Drink Table
EnquiryDayFoodDrinkId EnquiryDayId
20 5
21 6
Basically I want the distinct count to only return 1 as there is only one distinct enquiry with food + Drink attached.
Here is the code in SQL which return the correct number. I want to get the same result in Power BI
select count (distinct(e.pkEnquiries))
from EnquiryDayFoodDrink edfd
inner join EnquiryDay ed
on ed.EnquiryDayId = edfd.EnquiryDayId
inner join Enquiries e
on ed.EnquiryId = e.pkEnquiries