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
senright1989
New Member

Counting unique values in a column based on numerous values

Hi All, 

 

I have searched through this forum for a few hours today and for some reason i couldn't get what i am trying to do to work. 

 

I have the table called "Sample".

 

2017-08-02_22-45-15.jpg

 

 

 

 

 

 

 

 

 

 

 

I am looking to create a column where get a count of the number of times the pay item is entered in the table. For example pay item 1 would be 4. Pay item 2 would be 3. Pay item 3 would be 1. 

 

Then using this value I would be able to get the price per day for each entry instead of a total cost per each pay item. 

 

Any help would be appreciated with this.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Something like this?

Occurs = 
VAR PayItem = [Pay Item #]
RETURN
CALCULATE(
	countrows('YourTable'),
	ALL('YourTable'),
	'YourTable'[Pay Item #] = PayItem
)

View solution in original post

4 REPLIES 4
v-jiascu-msft
Employee
Employee

Hi @senright1989,

 

Could you please mark the proper answer as solution or share the solution if it's convenient for you? That will be a big help to the others.

 

Best Regards!
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
kaushikd
Resolver II
Resolver II

@senright1989

 

Hi for data refference i have taken your data( #Sample)

 

Capture.PNG

 

what your requirement is can be easily impleamented using a measure.

Step 1. R.click on the table and click New Measure

Step 2. Use this dax to calculate the count of Pay Item Count of Item = Count('Sample'[Pay Item])

Step 3. In the report page drop a table and select Date---Pay Item---Count of Item as the fields.

 

Please have a look what i have done here.Capture.PNG

 

 

If this is what you are looking for the please don't forget to mark this as a solution.

--Regards

   Kaushik

Anonymous
Not applicable

Something like this?

Occurs = 
VAR PayItem = [Pay Item #]
RETURN
CALCULATE(
	countrows('YourTable'),
	ALL('YourTable'),
	'YourTable'[Pay Item #] = PayItem
)

Thanks Ross, sorry for getting back so late but i will accept yor solution because I was able to use it in the end to get the result apart from one tweak.

 

Occurs =
VAR PayItem = MIN(Sheet1[Pay Item #])
RETURN
CALCULATE(
 countrows(Sheet1),
 ALL(Sheet1),
 Sheet1[Pay Item #] = PayItem
)

 

I had to add "MIN" because i was getting the following error:

 

A single value for column 'Pay Item #' in table 'Sheet1' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

 

I ended up using a much slower method intitially to get the job done for the interim. My co-worker showed me how to add an index column and group by the pay item with the countrows function in the query editor. For this to work i had to copy my whole data set and then merge it back in by adding columns. This worked fine but in the end it doubled my dataset and the load times were significantly increased.

 

Thanks again.

2017-08-21_9-22-00.jpg

 

 

 

 

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.