Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more
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:
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))
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