Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
natabird3
Skilled Sharer
Skilled Sharer

sum of values based on different text in another column - dynamic measure

Hello all,

 

I am having an issue, which i was thinking would be quite easy to solve but happened to be difficult creating a measure for. I want to create a few measures that specificly segment my different sales channels by a keyword. On a website when you buy a product it can come from Facebook, but also Facebook ref, Facebook int, etc. I would like to create a measure that will filter all traffic coming from "Facebook". If i wanted to get teh value in a filter is quite easy, advance filter and contains facebook, however how could i make this as a measure dynamically, as i would like to add a few of those in a bar chart visual comparing the different channels. 

 

Sample of the data would look like this:

UsersSource Medium
50000Facebook/ref
40000Facebook.int
235236Ebay.dasf
300Amazon.com
352Facebook,safasga
3500Amazon
2352Ebay

Output i would need the measure to get all users for any facebook mention (in this case 90352), then if i created another measure for the Amazon would be 3800. And potentially i would need one measure that will summarize all the remaining, but i think would be just the difference between the measures created and total. 

 

Hope you can help.

Thanks in advance for the help.

1 ACCEPTED SOLUTION

You can try

Facebook =
var _sel = "Facebook"
return
calculate(sum(Table[User]),Filter(all(Table),search(_sel,Table[Source Medium] ,1,0)>0))

OR

Facebook =
var _sel = "Facebook"
return
calculate(sum(Table[User]),Filter((Table),search(_sel,Table[Source Medium] ,1,0)>0))
Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

8 REPLIES 8
v-gizhi-msft
Community Support
Community Support

Hi,

 

According to your description, please take following steps:

1)Create a slicer table first:

110.PNG

2)Try this measure:

 

Measure = 
SUMX (
    DISTINCT ( 'Table'[Source Medium] ),
    IF (
        LEFT (
            'Table'[Source Medium],
            LEN ( SELECTEDVALUE ( 'Slicer Table'[Slicer Value] ) )
        )
            = SELECTEDVALUE ( 'Slicer Table'[Slicer Value] )
            && SELECTEDVALUE ( 'Slicer Table'[Slicer Value] ) <> BLANK (),
        CALCULATE ( SUM ( 'Table'[Users] ) )
    )
)

 

When you select one value in slicer, the result shows:

111.PNG

Here is my test pbix file:

pbix 

Hope this helps.

 

Best Regards,

Giotto Zhi

 

Dear Giotto @v-gizhi-msft ,

 

Thanks for the reply, however i didnt want to create a slicer as what i want to do is compare the values in a bar chart side by side. So what i would need is a distinct measure that will give me the value for each (key term that i am seraching in the source medium column), not a slicer that can go from one to the other, sorry but this is not solving my problem.

Hi,

 

Please try this calculated column:

 

Category = 
var t = MinX(ADDCOLUMNS({",","/","."},"Position",FIND([Value],'Table'[Source Medium],1,9999)),[Position])
REturn LEFT([Source Medium],IF(t= 9999,LEN('Table'[Source Medium]),t-1))

 

Choose this column and [Users] as a clustered bar chart, it shows:

121.PNG

Hope this helps.

 

Best Regards,

Giotto Zhi

Dear Giotto @v-gizhi-msft,

 

Maybe its just me, but where in the solution i am selecting which value to filter? This is displaying everything as if i put source medium column or what does it do?

 

Category =
var t = MinX(ADDCOLUMNS({",","/","."},"Facebook",FIND([Value],'Traffic Source'[Source / Medium],1,999999)),[Facebook])
REturn LEFT([Source / Medium],IF(t= 999999,LEN('Traffic Source'[Source / Medium]),t-1))
amitchandak
Super User
Super User

Try like

measure =
var _sel = allselected(values(Table[Source Medium]))
return
calculate(count(Table[User]),Filter(all(Table),search(_sel,Table[Source Medium] ,1,0)>0))



measure =
var _sel = maxx(allselected(Table),(Table[Source Medium]))
return
calculate(count(Table[User]),Filter(all(Table),search(_sel,Table[Source Medium] ,1,0)>0))

 

Better you move source medium to a new table and then join it use this kind of filter. Else all will remove all filters

Source = distinct (Table[Source Medium])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thank you for the quick reply @amitchandak , however in the proposed solution i do not understand how do i filter for say facebook or amazon values which are in the source/medium column? I am trying to select the actual user values for each of the specific terms, not a count of how many times it appears in the source medium column, hope this explains better.

You can try

Facebook =
var _sel = "Facebook"
return
calculate(sum(Table[User]),Filter(all(Table),search(_sel,Table[Source Medium] ,1,0)>0))

OR

Facebook =
var _sel = "Facebook"
return
calculate(sum(Table[User]),Filter((Table),search(_sel,Table[Source Medium] ,1,0)>0))
Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Exactly, what i needed thank you.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.