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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
hangbtt2
Frequent Visitor

Exclude user with condition from the chart

Hi everyone,

I have a problem that I hope you can help me with. I have user data tracked by events. I want the chart to filter out users who have at least one event_type=1 within a specified time period.

However, when I add this measure to a chart with the Y-axis as Month and Year, it doesn't work.

Here is the measure I wrote:

actions_by_user_not_having_event1 =
var cte = filter (SUMMARIZE( fact_event, fact_event[user_id],
                                                "MinEventType", CALCULATE(MIN(fact_event[event_type]), ALLSELECTED('Date'[Date])) ,
"events", COUNTROWS(fact_event) ), [MinEventType] > 1) return SUMX(cte, [events])
 
Thank you guys

hangbtt2_1-1718474141408.png

hangbtt2_2-1718474234117.png

 

2 ACCEPTED SOLUTIONS
MattAllington
Community Champion
Community Champion

It looks to me like you are using Date from the fact table in your formula and your visual (possibly the slicer, too). This is not the correct way to do it.

I missed the original point you made about the "selected period". You will need something like this (after you fix the calendar issues). I assume what you want is for the slicer to select the period and for the formula to remove anyone with the event =1 for the slicer period, not the monthly periods in the column chart. If that's not what you want, then this formula will need to change

= CALCULATE (
COUNTROWS ( fact_event ),
FILTER ( User, CALCULATE ( MIN ( factevent[eventtype] ) > 1 ) ),

ALLSELECTED(Date)
)

 

it may be that you need this, but I can't be sure. You would have to test both. 

= CALCULATE(CALCULATE (
COUNTROWS ( fact_event ),
FILTER ( User, CALCULATE ( MIN ( factevent[eventtype] ) > 1 ) ))

ALLSELECTED(Date)
)

 

also, do yourself a favour and get rid of the chart until it's working. Set up a matrix and add the same columns (month, event type).  It is much easier to debug the problems if you can see the numbers. 

after these changes, if you still can't sort it, post the workbook again and I will take a look.  I will be at my desk in about 1 hour

 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

View solution in original post

MattAllington
Community Champion
Community Champion

I have deployed what I suggested.  It appears to work to me.

https://www.dropbox.com/scl/fi/lg6xta1fr9magjehf3cfq/not_event_type_1.pbix?rlkey=e1ri52nt9xjk1yjdq8k...



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

View solution in original post

8 REPLIES 8
MattAllington
Community Champion
Community Champion

I have deployed what I suggested.  It appears to work to me.

https://www.dropbox.com/scl/fi/lg6xta1fr9magjehf3cfq/not_event_type_1.pbix?rlkey=e1ri52nt9xjk1yjdq8k...



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Thank you so much for your help Matt.

MattAllington
Community Champion
Community Champion

It looks to me like you are using Date from the fact table in your formula and your visual (possibly the slicer, too). This is not the correct way to do it.

I missed the original point you made about the "selected period". You will need something like this (after you fix the calendar issues). I assume what you want is for the slicer to select the period and for the formula to remove anyone with the event =1 for the slicer period, not the monthly periods in the column chart. If that's not what you want, then this formula will need to change

= CALCULATE (
COUNTROWS ( fact_event ),
FILTER ( User, CALCULATE ( MIN ( factevent[eventtype] ) > 1 ) ),

ALLSELECTED(Date)
)

 

it may be that you need this, but I can't be sure. You would have to test both. 

= CALCULATE(CALCULATE (
COUNTROWS ( fact_event ),
FILTER ( User, CALCULATE ( MIN ( factevent[eventtype] ) > 1 ) ))

ALLSELECTED(Date)
)

 

also, do yourself a favour and get rid of the chart until it's working. Set up a matrix and add the same columns (month, event type).  It is much easier to debug the problems if you can see the numbers. 

after these changes, if you still can't sort it, post the workbook again and I will take a look.  I will be at my desk in about 1 hour

 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.
MattAllington
Community Champion
Community Champion

See my previous point

"You can't solve this problem (reliably) without a user table."

 

create a user table, then it should work. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Hi Matt,

I followed your instruction and it works. But the thing is when event_type is added to the chart as legend, the measure goes wrong (without the legend, it works perfectly)

hangbtt2_0-1718564932379.png

 

test = CALCULATE (
COUNTROWS ( data ),
FILTER ( User, CALCULATE(MIN(data[event_type]), ALLSELECTED('date'[Date].[Month], 'date'[Date].[MonthNo]))> 1 )
)

Hi Matt, 

Thank you again with very quick response.

I follow you instruction but it didnt work yet. I think it is somehow affected by month-year filter context in the chart. Could you help me take a look at my dataset?

https://drive.google.com/drive/folders/1sLpG6WckCVyl4nEjADqw3V8KukFb-sd8?usp=sharing

hangbtt2_0-1718530227156.png

 

hangbtt2
Frequent Visitor

Hi Matt, Thank you so much for your promt response.

I dont think it works.

Here is the link to my dataset: https://drive.google.com/drive/folders/1sLpG6WckCVyl4nEjADqw3V8KukFb-sd8?usp=sharing

 

Thank you so much

MattAllington
Community Champion
Community Champion

I understand that DAX can be hard to learn. It's especially deceptive if you have a SQL background; most have to unlearn some concepts from SQL in order to become aware of the right approach in DAX.

 

As I understand the problem, you want a count of events, but exclude all events from users that have at least one event 1. Once you see a working solution, it's easy. "How" to think about this problem with respect to DAX is the real challenge. 

You don't mention if you have a star schema. If you don't, you need to get one. You can't solve this problem (reliably) without a user table.  

 

I don't know if this will work as I don't have any test data. If it doesn't, it should be close. 

= CALCULATE (
COUNTROWS ( fact_event ),
FILTER ( User, CALCULATE ( MIN ( factevent[eventtype] ) > 1 ) )
)

 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.