Forum Discussion
Cross filter ( to exclude )
- 5 years ago
Hi pbhat89 ,
Not sure what you mean by "I read online that we cannot reference variables from a temp table in power BI." but check the post below by SQLBI where they make references to how to use variables calculations and get data from those tables.
https://www.sqlbi.com/articles/table-and-column-references-using-dax-variables/
Regarding my second comment I was refering that you can use the new M query parameters to make a new table that picks up the slicer values filtering your data and then use that 3rd table to make your data visualization in conjunction with the slicer of the condition.
Check the blog post below:
https://blog.crossjoin.co.uk/2020/10/25/why-im-excited-about-dynamic-m-parameters-in-power-bi/
Since in actual case - i have many variables in table 1 which may be used as filters - could you advise something like :
Hi pbhat89 ,
As refered you need to place those variable inside the allselected
Calculation =
VAR temp_table =
FILTER (
ALLSELECTED ( Table1[ID]; Table1[Age]; table [column];...;table [columnzz] );
NOT ( Table1[ID] IN VALUES ( Table2[ID] ) )
)
RETURN
COUNTROWS ( temp_table )
- pbhat895 years agoHelper II
thanks MFelix - i did get it to work but with my actual dashboard but had to add if filtered argument to ensure apply not in only when any filters are selected in conditions table. my actual Data it gets far for more complex where i have many calculations apart from just count. These are conditional formulaes which make it difficult to write a code with requirements ( filtered and not in ) .
I simply want to get a table X ( subset of table 1 ) which updates as i
Part (A) : select the filters ( say Age , Height )
Part (B) : but has a different interaction (B) with table 2 -
- if table 2 is filtered ( one or more selected ) - then use the not in argument ( e.g. as shared by you earlier )
- if table has not been filtered ( nothing selected in conditions ) - table X should only show based on filters ( Age , Height ) and not
have any connection with Table 2.
Once this table X is generated / updated as i change parameters in part A or B - i can create all formulaes from this single table X. Its easy to get the filters part done (as the columns are within table 1) but with part B it becomes complex How can we create a dynamic table ( from queries ) which updates based on (A) and (B) above ?
- MFelix5 years agoSuper User
Hi pbhat89
If I understand you correctly what you need is if no values are selected in the slicer condition you should get 6 (with an age filter below 35) if values are selected you get the correct number:
Is this correct?
You just need to make the calculations based on your initial table in this case I'm using a count you must rewrite the formula to:
Calculation = VAR temp_table = FILTER ( ALLSELECTED ( Table1[ID]; Table1[Age] ); NOT ( Table1[ID] IN VALUES ( Table2[ID] ) ) ) RETURN IF ( ISFILTERED ( Table2[Condition] ); COUNTROWS ( temp_table ); COUNTROWS ( Table1 ) )Be aware that this selection ISFILTERED takes into account that you have any selection on the slicer condition so if you select A, B and C it will use the not if you deselect all of them it will use the table1.
Not sure if I have understood what you need but hope this is the result you need.
- pbhat895 years agoHelper II
Hi MFelix
Your understanding is correct and i have managed to get my formulaes in the form of syntax below.
(ignore the naming as this is based on my actual data )
dropped = (var ignore_count = COUNT(KO_input_template[ID])var select_count = CALCULATE(COUNT(KO_input_template[ID]),FILTER(KO_input_template,not(KO_input_template[ID] in values(input_db_disc_edited[ID]))))var fin_count= if(ISFILTERED(input_db_disc_edited[name])=TRUE,select_count,ignore_count)RETURN (fin_count))however as i mentioned, there are many follow up calculated fields which are based on the field above. What i wish for is a table which is generated rather i.e. table with the 6 OR the table with 4 rows as you show below. and for me to base all my calculations on that one table. that table updates as i set the filters ( Age , Height etc) or Select conditions ( or not select at all )How can i create such a dynamic table from my main tables with power query or dax or any other way? i also realized that if i create a temp table using var - i am unable to reference a variable [ID] from it my formulae.