Forum Discussion

zeebee48's avatar
zeebee48
Icon for Microsoft Employee rankMicrosoft Employee
5 years ago

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).

 

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

    • zeebee48's avatar
      zeebee48
      Icon for Microsoft Employee rankMicrosoft Employee

      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.