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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Yarisch77
Frequent Visitor

Dax on filtering duplicates and counting with text

Hi, I am struggeling with thefollowing table format:

 

Control NumberTitle
PPG-E0001A
PPG-E0001A
PPG-E0002C
PPG-E0002C
PPG-E0002C
PPG-A0001F
PPG-A0001F
PPG-A0001F
PPG-C0001I

 

I want to use a Dax function in order to do the following things:

 

1. Count only unique values of the Row Control Number (Not duplicates)

2. After that I want to be able count only the values which include for example "C" or "A" or "E"

 

At the end I should get a measure for example for "PPG-E" =  2 

 

I ve tried with DISTINCTCOUNT function but didnt get it.

 

To be honest I am a beginner with Power BI and would appreciate any help for this problem.

 

Thx for ur help

1 ACCEPTED SOLUTION
Anonymous
Not applicable

 Hi @Yarisch77 

 

this will take whole two months in account. 

It will take last date from previous month to today.

 

I think your requirement is same day from last month to today.

 

I have provided answer for the same.

 

Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar

If I resolve your problem Mark it as a solution and give kudos.

View solution in original post

13 REPLIES 13
az38
Community Champion
Community Champion

Hi @Yarisch77 

if i understand you correct

try measures:

1.

unique values = CALCULATE(DISTINCTCOUNT(Table[Control Number]))

2.

unique values by Title = CALCULATE(DISTINCTCOUNT(Table[Control Number]), ALLEXCEPT(Table, Table[Title]))

 

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Hi,

 

Thx for ur quick reply.  This goes into a good direction. I took ur idea and played around a little. AFter a while I got this:

 

Measure = CALCULATE(DISTINCTCOUNT('Table'[Control Number]);SEARCH("A";'Table'[Control Number];;-1)>0)
 
This worked well without counting duplicates and only counting with letter "E". Now I added 2 more rows with additional Infos => "Date" and "Status". The idea is to follow the above Measure but put two conditions: 
 
1. if "Date" is between for example "01.01.2019 and 20.01.2019"
2. and if "Status" is for example "Completed"
 
Thx in advance for ur help
Anonymous
Not applicable

Hi @Yarisch77 

Measure = CALCULATE(DISTINCTCOUNT('Table'[Control Number]),filter(table,SEARCH("A";'Table'[Control Number];;-1)>0 && table[date]>=date(2019,1,1) && table[date]<=date(2019,1,1) && table[Status]="Completed"))

 

Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar

If I resolve your problem Mark it as a solution and give kudos.

Hey,

 

Great formula, but it gave me a syntax error. Here's is the adapted formula with the original values from my company, may u see the error:

 

Measure 2 = CALCULATE(DISTINCTCOUNT('CPro Server'[Control Number]);filter('CPro Server'SEARCH("A";'CPro Server'[Control Number];;-1)>0 && 'CPro Server'[Action Request Due Date]>=date(2019;1;1) && 'CPro Server'[Action Request Due Date]<=date(2019;1;1) && 'CPro Server'[Status]="Completed"))
 
Thx in advance for ur help

 

Anonymous
Not applicable

Could you share what syntax error you got?

 

It may be some syntax issue like missing closing parenthesis or comma.

 

Thanks,

Pravin

It says....

 

Wrong Syntax für "SEARCH".(DAX(CALCULATE(DISTINCTCOUNT('CPro Server'[Control Number]),filter('CPro Server'SEARCH("A",'CPro Server'[Control Number],,-1)>0 && 'CPro Server'[Action Request Due Date]>=date(2019,1,1) && 'CPro Server'[Action Request Due Date]<=date(2019,1,1) && 'CPro Server'[Status]="Completed"))).)

Anonymous
Not applicable

Hi @Yarisch77 

 

you have missed comma (,) after table name in filter section.

 

Try to write dax by yourself step by step so that you will get know more about issue.

 

Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar

If I resolve your problem Mark it as a solution and give kudos.

Hey,

 

Thx a lot , works perfect now. Just one last question:

 

If i am going from this...

 

Measure 2 = CALCULATE(DISTINCTCOUNT('CPro Server'[Control Number]);filter('CPro Server';SEARCH("A";'CPro Server'[Control Number];;-1)>0 && 'CPro Server'[Action Request Due Date]>=date(2019;1;1) && 'CPro Server'[Action Request Due Date]<=date(2019;12;1) && 'CPro Server'[Status]="Completed"))
 
...and instead to define a date range I want to specify for example "last 30 days from today" or "comming 90 days from today", how do I do that???
 
Thx a lot in advance
Anonymous
Not applicable

Hi @Yarisch77 

 

Last 30 days or 1 month = CALCULATE(DISTINCTCOUNT('CPro Server'[Control Number]);filter('CPro Server';SEARCH("A";'CPro Server'[Control Number];;-1)>0 && 'CPro Server'[Action Request Due Date]>=dateadd(today(),-1,month) && 'CPro Server'[Action Request Due Date]<=Today() && 'CPro Server'[Status]="Completed"))

 

Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar

If I resolve your problem Mark it as a solution and give kudos.

 

Anonymous
Not applicable

Hi @Yarisch77 

instead of dateadd(today(),-1,month)

 you can use date(year(today()),month(today)-1,day(today()))

 

Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar

If I resolve your problem Mark it as a solution and give kudos.

This actually could also work, giving the same result for the las 60 days or not?

 

Measure 4 = CALCULATE(DISTINCTCOUNT('CPro Server'[Control Number]);filter('CPro Server';SEARCH("A";'CPro Server'[Control Number];;-1)>0 && 'CPro Server'[Action Request Due Date]>= EOMONTH(TODAY();-2) && 'CPro Server'[Action Request Due Date]<=Today() && 'CPro Server'[Status]="Completed"))
 
....
Anonymous
Not applicable

 Hi @Yarisch77 

 

this will take whole two months in account. 

It will take last date from previous month to today.

 

I think your requirement is same day from last month to today.

 

I have provided answer for the same.

 

Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar

If I resolve your problem Mark it as a solution and give kudos.

Thx for ur reply,

 

The formula gives me the following error:

 

The first argument to 'DATEADD' must specify a column

 

...

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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

Top Solution Authors
Top Kudoed Authors