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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Need Help with Filter & Calculate in Dax

Hi Everyone,

I'm trying to write a DAX expression in the pivot table and I could not figured out how to use the combination of Calculate, Filter & Count.

 

I need to exclude all User that has 1 or less transaction - I currently have this expression but the result is not correct: 

 

 

=if(
count([Type]) > 1, COUNT([Type]), 
blank())

 

 

 

The Data is as follows:

DepartmentUserSymbolType
A1AAATSLABuy
A1AAATSLABuy
A1CCCBCEBuy
A1DDDPWCBuy
B1AAAHBTSell
B1BBBBCEBuy
B1BBBHDSSell

 

Output should be, note User "CCC" & "DDD" are not populated because it has only 1 count:

DepartmentUserTypeSymbolCount
A1AAABuyTSLA2
  SellHBT1
B1BBBBuyBCE1
  SellHDS1

 

Hope you can help!

 

2 REPLIES 2
Anonymous
Not applicable

[Exclude User] =
var __userFiltered = ISFILTERED( Data[User] )
var __oneUserVisible = HASONEVALUE( Data[User] )
var __totalTranCount =
	CALCULATE(
		COUNTROWS( Data ),
		ALLEXCEPT( Data, Data[User] )
	)
var __shouldExclude = __totalTranCount <= 1
var __finalCondition =
	__userFiltered
	&& __oneUserVisible
	&& __shouldExclude
return
	if( __finalCondition, __shouldExclude )

This measure tells you if you should exclude the user (TRUE) or not (FALSE). You can put this measure in your pivot and filter by it leaving only those users for which the measure returns FALSE (meaning: don't exclude).

 

Best

D

Greg_Deckler
Super User
Super User

Maybe:

 

Measure =
  VAR __Table = 
    SELECTCOLUMNS(
      FILTER(
        SUMMARIZE(
          ALL('Table'),
          [User],
          "__Count',COUNTROWS('Table')
        ),
        [__Count] < 2
      ),
      "User",
      [User]
    )
RETURN
  IF(MAX('Table'[User] IN __Table,0,1)

 

Then use that as a filter.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors