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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
KunalKochar
Frequent Visitor

Query Regarding DAX

Hello All,

I am new to Power BI and stuck at a problem:

Attached is an screenshot of an example sample data. I need to find out the count of users who 'only' performed event 'B'
So, as per the example given, the output should be one user, because user 3 performed only event 'B'.
Any idea how can I write DAX query for this problem?

 

KunalKochar_0-1654634428502.png

 

2 ACCEPTED SOLUTIONS
v-eqin-msft
Community Support
Community Support

Hi @KunalKochar ,

 

You could create a flag measure:

Flag = 
var _dis=CALCULATE(DISTINCTCOUNT('Table'[Event]),ALLEXCEPT('Table','Table'[User]))
var _countB=CALCULATE(COUNTROWS('Table'),FILTER('Table',[User]=MAX('Table'[User]) && [Event]="B"))
RETURN IF(_dis=1 && _countB>0,1,0)

And then apply it to visual-level filter pane, set as "=1":

Eyelyn9_0-1654840465239.png

 

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

 

View solution in original post

v-eqin-msft
Community Support
Community Support

Hi @KunalKochar ,

 

Did my method help you ? Please feel free to ask.

 

Best Regards,
Eyelyn Qin

View solution in original post

7 REPLIES 7
v-eqin-msft
Community Support
Community Support

Hi @KunalKochar ,

 

Did my method help you ? Please feel free to ask.

 

Best Regards,
Eyelyn Qin

v-eqin-msft
Community Support
Community Support

Hi @KunalKochar ,

 

You could create a flag measure:

Flag = 
var _dis=CALCULATE(DISTINCTCOUNT('Table'[Event]),ALLEXCEPT('Table','Table'[User]))
var _countB=CALCULATE(COUNTROWS('Table'),FILTER('Table',[User]=MAX('Table'[User]) && [Event]="B"))
RETURN IF(_dis=1 && _countB>0,1,0)

And then apply it to visual-level filter pane, set as "=1":

Eyelyn9_0-1654840465239.png

 

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

 

KunalKochar
Frequent Visitor

Hi @tackytechtom 
Thanks for your reply!

But, applying your solution gives an answer of 3, because there are three users in total who performed event = B.
I need users who performed 'only' event 'B', in this case only user '3'

Hi @KunalKochar ,

 

My bad! I did not read your requirement properly. 

 

How about this one here:

Measure = 
VAR _helpTable = 
SUMMARIZE (
    Table,
    Table[User],
    "CountEventB", COUNTROWS ( FILTER ( Table, Table[Event] = "B") ),
    "CountOtherEvents", COUNTROWS ( FILTER ( Table, Table[Event] <> "B") )
)
RETURN
COUNTROWS ( FILTER ( _helpTable, [CountEventB] >= 1 && [CountOtherEvents] = 0 ) )

 

The idea is to create a _helpTable variable which would return the following result:

tomfox_0-1654715637543.png

 

From there it is just choosing the one that has value >= 1 in the first column and a value that equals 0 (or BLANK) in the second column.

 

Let me know if this helps or if you have any questions 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Dear @tackytechtom 
Thanks for the answer, I applied the same concept as this and it worked. Please find the DAX below. Although I have two follow-up questions on this, hoping you could answer this as well,
1. What if I have the user column in different table and not in 'Data' table I tried, VAR B_Users = CALCULATETABLE ( DISTINCT ( DifferentTable[User] ), Data[Event] = "B" ) But this is giving me blank output.
2. To extend my original question, what if I want to calculate list of users who performed only event B or C or more than two events? Do I have to manually write the above DAX for each event and then count distinct user id

VAR B_Users = CALCULATETABLE ( DISTINCT ( Data[User] ), Data[Event] = "B" )

VAR Non_B_Users = CALCULATETABLE ( DISTINCT ( Data[User] ), Data[Event] <> "B" )

VAR B_Only_Users = EXCEPT ( B_Users, Non_B_Users )

RETURN COUNTROWS ( B_Only_Users )

 

wdx223_Daniel
Super User
Super User

NewTable=FILTER(VALUES(table[User]),CALCULATE(DISTINCTCOUNT(table[Event]))=1)

tackytechtom
Super User
Super User

Hi @KunalKochar ,

 

How about this:

Measure = COUNTROWS ( FILTER ( Table, Table[Event] = "B") )

 

Let mw know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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