PowerBI - AllSelected problem when multiple rows are involved

860 Views Asked by At

I'm developing a PowerBI report in DirectQuery. I introduced a measure with the syntax ALLSelected (RemoveFilters) because I need to calculate some data removing a contextual filter based on the relationship between two tables. It works, but only when one rows is involved (for example, putting a specific filter on a column "Country"). If more countries are involved, the value for each row is the sum of all the rows involved (so, the number is always the same for all the rows). It seems that PowerBI is not able anymore with AllSelected function to "group by" the data.

mes_CountData = 
VAR FirstFilter = MIN( pbi_Table1[Code1] )
VAR SecondFilter = MIN( pbi_Table1[Code2] )
VAR ThisRows = CALCULATE(COUNTROWS( FILTER(ALLSELECTED(pbi_Table1), pbi_Table1[Code1] <> FirstFilter && pbi_Table1[Code2] = SecondFilter), REMOVEFILTERS(pbi_Table1[OriginalCode]))

return ThisRows

How can I fix it? Any solutions or ideas are welcome.

1

There are 1 best solutions below

1
On

I have no idea how REMOVEFILTERS( pbi_Table1[OriginalCode]) influence on your data model. May be if you change the transfomation order and do like this it will help:

mes_CountData = 
VAR FirstFilter = MIN( pbi_Table1[Code1] )
VAR SecondFilter = MIN( pbi_Table1[Code2] )
VAR allSelectedTable = 
    FILTER(
              ALLSELECTED(pbi_Table1)
              ,pbi_Table1[Code1] <> FirstFilter && pbi_Table1[Code2] = SecondFilter
        )   
VAR ThisRows = 
       CALCULATE(
                 COUNTROWS(allSelectedTable) 
                ,REMOVEFILTERS(pbi_Table1[OriginalCode])
       )
return ThisRows