Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
Sign up nowGet Fabric certified for FREE! Don't miss your chance! Learn more
Hi,
We are using SSAS tabular model as a data source for PowerBI. I have the below scenario and i am trying to write dax formule for it. Any help is much appreciated
Example
We have two tables(Students,enrollment) which does not have a direct relationship. ‘Student’ table should be filtered on a condition where student age should be greater than X years . ‘Enrollment’ table has three conditions on different columns. I need to get distinct ‘studentid’ from enrollment(as each student have multiple enrollments) and pass it ‘Student’ table and calculate the count of records matching conditions from both tables.
Example
We have two tables(Students,Services) which does have a direct relationship. The tables are connected on studentid column .‘Student’ table should be filtered on a condition where status code is 1 or 2 in a column . I need to calculate count of distinct students with filtered students from prior conditions(students table) does not have some particular services(eg: service number 100,200). Each student will have multiple services
Student Table
StudentId | Student Birth date | Status code |
|
|
|
|
|
|
Service Table
Sno | StudentId | Service number |
|
|
|
|
|
|
Enrollment Table
Enrollment Number | StudentId | Column 1 | Column2 | Column 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Thanks
Solved! Go to Solution.
When two tables (Student, Enrollment) are not related, we can use FILTER() in calculate relate tables in DAX without using relationships. See: How to relate tables in DAX without using relationships. Please refer to following steps:
Student Age = ROUNDDOWN ( ( TODAY () - Student[Student Birth date] ) / 365, 0 )
Distinct_ID_Age_Conditions =
IF (
Student[Student Age] > 23,
CALCULATE (
COUNT ( Enrollment[StudentId] ),
FILTER (
Enrollment,
Enrollment[Column 1] = "A"
&& Enrollment[Column 2] = "A"
&& Enrollment[Column 3] = "A"
&& Student[StudentId] = Enrollment[StudentId]
)
),
BLANK ()
)
Count_Of_Records = COUNTROWS ( Student ) - COUNTBLANK ( Student[Distinct_ID_Age_Conditions] )
When two tables (Student, Service) are related, we can use RELATED() function to calculate. Please refer to following steps.
Have_Particular_Services =
IF (
CALCULATE (
COUNTROWS ( Service ),
Service[Service number] = 100
|| Service[Service number] = 200,
ALLEXCEPT ( Service, Service[StudentId] )
)
> 0,
TRUE (),
FALSE ()
)
Distinct_ID_No_Ser_100_200 =
CALCULATE (
DISTINCTCOUNT ( Service[StudentId] ),
Service[Have_Particular_Services] = FALSE (),
ALLEXCEPT ( Service, Service[StudentId] ),
FILTER (
Service,
RELATED ( Student[Status code] ) = 1
|| RELATED ( Student[Status code] ) = 2
)
)
I have also attached the .pbix file.
Check out my blog post here:
Hi,
We are using SSAS tabular model as a data source for PowerBI. I have the below scenario and i am trying to write dax formule for it. Any help is much appreciated
Example
We have two tables(Students,enrollment) which does not have a direct relationship. ‘Student’ table should be filtered on a condition where student age should be greater than X years . ‘Enrollment’ table has three conditions on different columns. I need to get distinct ‘studentid’ from enrollment(as each student have multiple enrollments) and pass it ‘Student’ table and calculate the count of records matching conditions from both tables.
Example
We have two tables(Students,Services) which does have a direct relationship. The tables are connected on studentid column .‘Student’ table should be filtered on a condition where status code is 1 or 2 in a column . I need to calculate count of distinct students with filtered students from prior conditions(students table) does not have some particular services(eg: service number 100,200). Each student will have multiple services
Student Table
StudentId | Student Birth date | Status code |
|
|
|
|
|
|
Service Table
Sno | StudentId | Service number |
|
|
|
|
|
|
Enrollment Table
Enrollment Number | StudentId | Column 1 | Column2 | Column 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Thanks
Check out my blog post here:
Sorry could not reply sooner as i was on vacation
Thanks for the reply. I will follow the link and try to implement.
Venu Jasti
When two tables (Student, Enrollment) are not related, we can use FILTER() in calculate relate tables in DAX without using relationships. See: How to relate tables in DAX without using relationships. Please refer to following steps:
Student Age = ROUNDDOWN ( ( TODAY () - Student[Student Birth date] ) / 365, 0 )
Distinct_ID_Age_Conditions =
IF (
Student[Student Age] > 23,
CALCULATE (
COUNT ( Enrollment[StudentId] ),
FILTER (
Enrollment,
Enrollment[Column 1] = "A"
&& Enrollment[Column 2] = "A"
&& Enrollment[Column 3] = "A"
&& Student[StudentId] = Enrollment[StudentId]
)
),
BLANK ()
)
Count_Of_Records = COUNTROWS ( Student ) - COUNTBLANK ( Student[Distinct_ID_Age_Conditions] )
When two tables (Student, Service) are related, we can use RELATED() function to calculate. Please refer to following steps.
Have_Particular_Services =
IF (
CALCULATE (
COUNTROWS ( Service ),
Service[Service number] = 100
|| Service[Service number] = 200,
ALLEXCEPT ( Service, Service[StudentId] )
)
> 0,
TRUE (),
FALSE ()
)
Distinct_ID_No_Ser_100_200 =
CALCULATE (
DISTINCTCOUNT ( Service[StudentId] ),
Service[Have_Particular_Services] = FALSE (),
ALLEXCEPT ( Service, Service[StudentId] ),
FILTER (
Service,
RELATED ( Student[Status code] ) = 1
|| RELATED ( Student[Status code] ) = 2
)
)
I have also attached the .pbix file.
Thanks , the solution worked for me
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 63 | |
| 62 | |
| 42 | |
| 19 | |
| 16 |
| User | Count |
|---|---|
| 111 | |
| 104 | |
| 36 | |
| 28 | |
| 27 |