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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
gabrielrosa
Frequent Visitor

How to count two columns with names without repeating?

Hello, friends.

 

I have a problem. 

 

I have a data base of production, and every machine entry I have the name of the operator who was producing on this.

But, some days, I have two operator in just one machine. Then, the entry come like "A,B", and I just used "separate after delimiter". By the way, this "A or B" operador, can appear in another entry if they went to another machine to produce alone.

This way, I have two columns. But I want to count these two columns and show "HOW MANY OPERATORS WORKED THIS DAY" without repeating a operator.

 

 

PROBLEM.png

 

1 ACCEPTED SOLUTION

Hi,

In the Query Editor, right click on the Operadores column and select Split column.  Split by rows there.  Create a Calendar Table and build a relationship from the Data column to the Date column of the Calendar Table.  Create a slicer from the Date column of the Calendar Table and select any date there.  Write this measure

=DISTINCTCOUNT('Table1'[Operadores])

Hope this helps.

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

10 REPLIES 10
Greg_Deckler
Super User
Super User

If possible, in Query Editor, unpivot Column 2 and Column 3 and then this should be simple. Otherwise, if for some reason that is not possible, you could do this in DAX:

 

Distinct Count =
  VAR __Table = 
    UNION(
      SELECTCOLUMNS('Table',"Operator 1",[OPERATOR 1]),
      SELECTCOLUMNS('Table',"Operator 2",[OPERATOR 2])
    )
RETURN
  COUNTROWS(DISTINCT(__Table))

 


Follow on LinkedIn
@ 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...

I can delete columns 2 and 3, So I have the original entry.

 

probm.png

 

Hi,

In the Query Editor, right click on the Operadores column and select Split column.  Split by rows there.  Create a Calendar Table and build a relationship from the Data column to the Date column of the Calendar Table.  Create a slicer from the Date column of the Calendar Table and select any date there.  Write this measure

=DISTINCTCOUNT('Table1'[Operadores])

Hope this helps.

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Can you post sample data as text so I can test? Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 


Follow on LinkedIn
@ 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...

Ok! Here it is.

 

DATAMÁQUINAOPERADORESPRODUÇÃO
10/01/20201A,B1
10/01/20202C1
10/01/20203D1
10/01/20204E1
10/01/20205A1
10/01/20206B1
11/01/20201A1
11/01/20202C,B1
11/01/20203D1
11/01/20204E1
11/01/20205B1
nullnullnullnull

 

Hi,

Did you try my solution?

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hey, Ashish! 

 

It worked!

Thank you so much for the insight!

However, I have to create a copy of the database with only the dates and names of the operators, cause dividing the row, the production column is divided too, like this:

 

DATEOPERATORPRODUCTION
16/03A , B10

 

After dividing:

 

DATEOPERATORPRODUCTION
16/0310
16/03B10

 

But no problem. It's a solution!

 

Thank you so much.

 

 

 

You are welcome.

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hello! 

 

Thanks for answer. 

 

But unfortunately didn't worked 😞

 

Still counting all the values...

 

probl2.png

 

I made a measure, is it right?

 

I just did a measure, is it right?I just did a measure, is it right?

 

Hi Gabriel,

I think the issue is that I will add the blanks as a seperate distinct value.  Which is why your count is off by 1.

You could try something like this to filter out the empty field value.  

DISTINCT =
VAR __TABLE =
    FILTER (
        UNION ( VALUES ( 'Table'[operator 1] ); VALUES ( 'Table'[operator 2] ) );
        LEN ( [ALFA] ) > 0
    )
RETURN
    COUNTROWS ( __TABLE )

 Best regards,

Jeroen Dekker

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.