Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. 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.
User | Count |
---|---|
14 | |
9 | |
7 | |
7 | |
6 |
User | Count |
---|---|
21 | |
11 | |
10 | |
10 | |
8 |