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
justmeakinna
Frequent Visitor

Measure: Calculate how often a filtered value appears in entire dataset

Hey, so I have been trying to get a DAX code to work for my problem, however, I have not yet been successful.

 

Wanted

I want to calculate how often a value in a table (using filters) occurs in the entire dataset. 

 

What do I have

So I have a database that contains both folder names and file names, they are distinguishable by a column that states if they are either folder of file. From this, I can create a table that shows all folder names and folder paths (a different column). Now I want to calculate how often this same folder path (from a folder name) occurs in a folder path of file name. 

 

Let me include an example of my dataset:

dataset.PNG

So I have a table in my report filtered on item_type = Folder and want to add a count after it that tells me how often that uri_source is present for item_type = File.

filename documents should then return 2 (for test1.txt and test2.txt) and filename photos should return 1 (for test.png)

 

What have I tried

I have tried various DAX measures but none of them successful, here are two of my measures.

Folders = CALCULATE(COUNTROWS(data); FILTER(DATA; SEARCH(data[uri_source]; ALL(data[uri_source]);;0)>0))

Folders = CALCULATE(COUNTROWS(data),SEARCH(data[uri_source], ALL(data[uri_source]), 1, 0) > 0)
 
I have tried slight modifications of these as well. They either already show an error when inputting the formula, or when adding the measure to the table with item_type = Folder and return the error "A table of multiple values was supplied where a single value was expected"
 
I hope you guys can help me out here!

 

1 REPLY 1
Anonymous
Not applicable

Create 2 tables: 1) Folders will store folders only (Uri, Folder Name), 2) Files (Uri, File Name).

They will not be joined on anything.

 

Uri will be the unique identifier for the tables. You should also make active the setting on Folders that will instruct PBI not to aggregate the same Folder Names because 2 different Uri's might have the same Folder Name. You probably don't want to aggregate them.

 

Create a measure (this works on an individual folder level):

[File Count] =
var __folderName = selectedvalue( Folders[Uri] )
return
	countrows(
		filter(
			all( Files ),
			containsstring(
				Files[Uri],
				__folderName
			)
		)
	)

 If you want this measure to work for a selection of folders, then you'll have to iterate this measure over the visible Folders[Uri]'s.

 

Best

D

 

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