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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
zeebee48
Microsoft Employee
Microsoft Employee

DAX code not working with config variable used in a measure

I have a table (named Proto) in power-bi desktop as shown below (with 4 columns & around 30k rows).

 
zeebee48_1-1626068708631.png

I created a measure with the following DAX code. Here, ProtoVal is a table of single column containing unique values of protocol (like SSL, DNS etc). Based on the user selected protocol, i am filtering the above table to contain rows only for the selected protocol.

 

ProtoTotBytes =
VAR SelectedProto = SELECTEDVALUE(ProtoVal[Protocol])
VAR temp1 = FILTER(Proto, Proto[Protocol] == SelectedProto)
RETURN CALCULATE(SUM(Proto[total_bytes]), temp1)

 

The above DAX code works fine. Now in addition to SelectedProto, i wanted to add one more config variable numIP (TopN-IP's being a table of single column containing numerical values 5,10,15,20 etcTopN-IP's = GENERATESERIES(5, 30, 5)) where i want to take only the top 'numIP' rows from table temp1. Wrote the code below for that. This works whenever i change the value of SelectedProto but doesn't change when i change numIP ? Can anyone please let me know whey its sensitive to one config variable while it is ignoring another ?

 

ProtoTotBytes =
VAR numIP = SELECTEDVALUE('TopN-IP''s'[TopN-IP's])
VAR SelectedProto = SELECTEDVALUE(ProtoVal[Protocol])
VAR temp1 = FILTER(Proto, Proto[Protocol] == SelectedProto)
VAR temp2 = TOPN(numIP, temp1, [total_bytes], DESC)
RETURN CALCULATE(SUM(Proto[total_bytes]), temp2)

 

 

2 REPLIES 2
amitchandak
Super User
Super User

@zeebee48 , I think You should prefer to use a measure and values with topn

 

example

ProtoTotBytes TOPN =
VAR temp2 = TOPN(numIP, alllselected(Proto), [ProtoTotBytes], DESC)
RETURN CALCULATE(SUM(Proto[total_bytes]), temp2 , values(Proto))

 

prefer values to be the column in place of table

 

 

refer if needed

TOPN: https://www.youtube.com/watch?v=QIVEFp-QiOk&list=PLPaNVDMhUXGaaqV92SBD5X2hk3TMNlHhb&index=42

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

Thanks @amitchandak , your solution worked but still i am not sure what was wrong with my solution. Logically it seemed correct...can't we have two config variables for the same measure...can you please help me understand on what was the issue in my approach ? Went through the youtube link you shared, that was useful but would like to know the issue with my approach. Thanks.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors