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
niko18033
Helper I
Helper I

Column to toggle between single or multiple categories

I want to create a column that allows me to toggle between emails associated with single or multiple clients (categories). I have a stacked column chart with the following fields.

 

Axis: 'Email'

Legend: 'Client'

Values: 'Request Count' 

 

Currently, the chart is plotting counts by 'Email' for all 'Clients' including those which just a single client.

Ideally, I'd like to filter to only the emails which have more than 1 client associated with them.

 

Below is an example (all emails are encrypted). The emails highlighted yellow would remain, as they have counts for multiple clientsHowever, I'd like to filter out the emails with the red line through them, as they are associated with just a single client (single-color bars)

niko18033_2-1597792389928.png

 

Any assistance in writing a DAX formula to achieve this filter would be much appreciated! Please let me know if you need me to provide any further details.

11 REPLIES 11
Anonymous
Not applicable

You have to have a dimension 'Emails' and one of the attributes must be the number of clients where the values would be 'Single' and 'Multiple'. You'll then place the EmailID on the axis and filter by one of the values. The chart will then show on the x-axis only the filtered emails. You can't achieve what you want through a measure.
amitchandak
Super User
Super User

@niko18033 , Try measure like, Assumed you already have measure Request Count

 

sumx(filter(summarize(Table, Table[Email],"_1",count(Table[Client]),"_1",[Request Count]),[_1]>1),[Request Count])

or

sumx(filter(summarize(Table, Table[Email],"_1",distinctcount(Table[Client]),"_1",[Request Count]),[_1]>1),[Request Count])

vivran22
Community Champion
Community Champion

Hello @niko18033 ,

 

May I request you to share the sample table structure from which you are plotting the visual. It will help in writing appropriate DAX.

 

Cheers!
Vivek

Blog: vivran.in/my-blog
Connect on LinkedIn
Follow on Twitter

Hi Vivek - Thanks for your quick reply. Below is a sample export of the data. The emails which are essentially duplicates in this table (have a row for more than one client) are the ones I want to keep.

 

Request Count is a measure. = DISTINCTCOUNT(requests)

 

EmailClient Request Count
00539XAKOIOYVFPFPE@KNDUB.JABClient A 2
014RMOIJIJ@FEPGS.PIHClient A 2
0174@YGH.UHYClient A 3
0174@YGH.UHYClient B 3
03UFWTEN@RPCFF.EEUClient C 2
0598JN@ZXOPY.CUDClient D 9
07FBTAUYMNE@AAOXR.DUGClient C 2
07LANWWAN@SNWVM.AADClient A 3
07LANWWAN@SNWVM.AADClient C 3
08VMURWVXTAALNQFM@IYCPY.LHKClient A 2
0CX7YA@AQSJU.TKGClient A 5
0KHXZYFWILP@VDLDK.KXDClient A 2
0ZRESSS@DXX.OIHClient A 2
1268EO@VBZAE.CBTClient A 3
1268EO@VBZAE.CBTClient D 2
142.LAHYEYNZMOTAR@JIAJK.JMWClient D 2
1628UUEBQ@ZRPTX.OICClient A 2
171YVA@FRTPW.YYWClient A 2
178N369@APXQS.FUWClient B 2
178N369@APXQS.FUWClient A 2

 

Anonymous
Not applicable

[Email Type] = // calculated column
var __email = T[Email] // T is the table
var __howMany =
    countrows(
        filter(
            T,
            T[Email] = __email
        )
    )
return
    If( __howMany > 1, "Multiple", "Single" )

Here is your attribute...

Anonymous
Not applicable

By the way, creating a measure - as vivran22 suggests - will be of no use to you in this regard. Secondly, this calculation should ideally be performed in Power Query since this piece of Power BI has been designed to efficiently deal with such problems through the M language. On top of that, if you do it in DAX, as I did above, the compression rate will not be optimal (but it might suffice). Please note that all preprocessing should be always performed in Power Query, not in DAX. DAX is a Data Analysis eXpressions language, not a data mashup language like M.

 

The fact that something is doable does not necessarily mean it should be done.

@niko18033 

 

You may try this as a measure:

 

Multiple Clients = 
//Create a summary table
VAR _StepTable = 
    SUMMARIZE(
        'Email Table',
        'Email Table'[Email],
        "Client Count", DISTINCTCOUNT('Email Table'[Client]),
        "Request Count", SUM('Email Table'[Request Count])
    )
//Filter out records with single client
VAR _Filter = 
    FILTER(_StepTable,
        [Client Count] > 1
    )

//Get the sum of request count for emails with multiple clients
VAR _SumOfRequest = 
    SUMX(_Filter,[Request Count])
RETURN
_SumOfRequest

 

 

Cheers!
Vivek

If it helps, please mark it as a solution. Kudos would be a cherry on the top 🙂
If it doesn't, then please share a sample data along with the expected results (preferably an excel file and not an image)

Blog: vivran.in/my-blog
Connect on LinkedIn
Follow on Twitter

@vivran22 

Thanks, Vivek. I tried that, but it seems to be extremely processor/RAM intensive. It ran for almost an hour but failed due a lack of system resources. I tried a workaround, by creating a column rather than a measure. This way, the user also has the option whethere or not to filter out the "single" client emails. I'm trying to do a column that yields two values: "Single" or "Multiple", referring to the number of clients associated with the email.

 

However, I'm getting this error. Am I missing something?

"The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value."

 

Multiple Clients? =
VAR StepTable =
SUMMARIZE(
'Table1',
Table1[Email],
"Client Count", DISTINCTCOUNT('Table1'[CLIENT_NAME]),
"Request Count", [Request Count])
//Filter out records with single client
RETURN
IF(FILTER(StepTable, [Client Count] > 1), "Multiple", "Single")
 
 

 

@niko18033 

 

What is your data source, Excel, SQL? And how many records in total (estimate)?

 

Cheers!
Vivek

Blog: vivran.in/my-blog
Connect on LinkedIn
Follow on Twitter

Anonymous
Not applicable

As I said above, you have to add an attribute to your table that for each email will tell you whether it's a 'single' one or 'multiple' one. Then and only then will you be able to slice via this attribute and the x-axis of your visual will adjust accordingly.

Thanks for the follow-up, @Anonymous . What would be the best way to create such an attribute? Through Power Query Editor and doing a 'Group By' aggregation? Or a conditional column? I was thinking of just writing a DAX column, but am unsure how to define this.

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