Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
pickslides
Helper I
Helper I

Looking up values across different tables

Hi, I have two tables. One is a list of students the other a list of activities. I wish to count (in DAX) the number of distinct activities they have choosen if they are "Co-curirrcular" (Green). I have the output column in yellow and red values.

 Power BI Snip#1.PNG

 

 

 

Thanks Q

 

8 REPLIES 8
v-yangliu-msft
Community Support
Community Support

Hi  @pickslides ,

Here are the steps you can follow:

1. Create calculated column.

TABLE Participation:

 

Flag1 =
var _flag1=IF(
    'TABLE Participation'[Category]="Co-Curricular Activities",1,0)
return
SUMX(
    FILTER(ALL('TABLE Participation'),
    'TABLE Participation'[Perferred]=EARLIER('TABLE Participation'[Perferred]) &&'TABLE Participation'[Category]=EARLIER('TABLE Participation'[Category]) ),_flag1)

 

vyangliumsft_0-1656488859754.png

Table Student:

 

Count =
var _if1=
IF(
   NOT( ISBLANK(
CALCULATE(
    MAX('TABLE Participation'[Perferred]),FILTER(ALL('TABLE Participation'),
    'TABLE Participation'[UID]='Table Student'[UID])))),
    CALCULATE(MAX('TABLE Participation'[Flag1]),FILTER(all('TABLE Participation'),'TABLE Participation'[UID]=EARLIER('Table Student'[UID]))))
    return
IF(
    _if1 =0,BLANK(),_if1)

 

2. Result:

vyangliumsft_1-1656488859756.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

pickslides
Helper I
Helper I

A-ha.. I found a typo in the formula. Seems to work now. 

 

If the result is zero, cells are blank, can I populate with 0 somehow?

 

Q

@pickslides 

Yes you can

Count =
COUNTROWS (
    FILTER (
        Participation,
        Participation[Category] = "Co-curirrcular"
            && Participation[Preferred] = Sudent[Preferred]
    )
) + 0

@pickslides 

Two questions: do you have relationship between the two tables? Are you creating a calculated coumn in the student table?

tamerj1
Super User
Super User

Hi @pickslides 

please try

Count =
COUNTROWS (
    FILTER (
        Participation,
        Participation[Category] = "Co-curirrcular"
            && Participation[Preferred] = Sudent[Preferred]
    )
)

 

This didnt work but it didnt give me an error. Thanks!

@pickslides 

Do you have any relationship between the two tables?

Yes, I have a one to many relationship on the UID field

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.