Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
I created a calculated column to count number of sites in each product and its working
Sites Count = //Number of Sites in each product
VAR str = SELECTEDVALUE(product[Site Key])
VAR str_len = LEN(str)
RETURN
IF(str_len>1, ((str_len - LEN(SUBSTITUTE(str, "||", "")))/2 + 1),0)
Now I have to calculate total number of sites in all product.
All Product Site Count = //Total number of Sites in all products
VAR str = SELECTEDVALUE(product[Site Key])
VAR str_len = LEN(str)
RETURN
CALCULATE(((str_len - LEN(SUBSTITUTE(str, "||", "")))/2 + 1), REMOVEFILTERS())
But All product site count is not giving expected output
Sample data and expected site count columns are
Product key | Site key | Site Count |
2 | 83 | 1 |
3 | 67||83 | 2 |
8 | 44||56||91||45||67||99 | 6 |
7 | 0 | |
4 | 91||56||83 | 3 |
All product site count should return 12 for above sample data.
someone please help here ?
Hi @Hari01
Please refer top attached sample file with two proposed solutions
Site Count 1 =
VAR String =
CONCATENATEX (
VALUES ( 'Table'[Site key] ),
'Table'[Site key],
"|"
)
VAR Items = SUBSTITUTE ( String, "||", "|" )
VAR Length = PATHLENGTH ( Items )
VAR T1 = GENERATESERIES ( 1, Length, 1 )
VAR T2 = SELECTCOLUMNS ( T1, "@SiteKey", PATHITEM ( Items, [Value] ) )
RETURN
IF (
String <> BLANK ( ),
COUNTROWS ( T2 )
)
Site Count 2 =
VAR String =
CONCATENATEX (
VALUES ( 'Table'[Site key] ),
'Table'[Site key],
"|"
)
VAR Items = SUBSTITUTE ( String, "||", "|" )
VAR Length = PATHLENGTH ( Items )
VAR T1 = GENERATESERIES ( 1, Length, 1 )
VAR T2 = SELECTCOLUMNS ( T1, "@SiteKey", PATHITEM ( Items, [Value] ) )
RETURN
IF (
String <> BLANK ( ),
COUNTROWS ( DISTINCT ( T2 ) )
)
hi @Hari01
Are you writing a measure for All Product Site Count?
Try like:
yes, I'm trying to write a measure to sum all values of Sites Count.
Sumx is not working. Got zero
@Hari01 First, please vote for this idea: https://ideas.powerbi.com/ideas/idea/?ideaid=082203f1-594f-4ba7-ac87-bb91096c742e
This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376
Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907
Also: https://youtu.be/uXRriTN0cfY
And: https://youtu.be/n4TYhF2ARe8
Hi @Hari01
Shouldn't this be a distinct count? Seems to me 8 is more realistic than 12
I don't want distinct count.
@Hari01
Ok have you checked my solution with the sample file? I gave both options; normal count and distinct count.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
10 | |
10 | |
10 | |
10 |
User | Count |
---|---|
19 | |
14 | |
13 | |
11 | |
8 |