Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

using less or equal in filter

Hi,

 

In a source table I have a field that contains a number between 1 and 50.

In a page I want to show its records using a table vizualisation.

I want to use a slicer with the values 5, 10, 15, 20, 25, ..., 50

If I select e.g. the value 20 in the slicer, then in the table I get all records with the number 1 to 20

If I select e.g. the value 35 in the slicer, then in the table I get all records with the number 1 to 35

etc.

 

I tried to add a new column =(TRUNC((number-1)/5)+1)*5, but selecting 20 in the slicer, then in the table I get only the records with number 16 to 20, selecting 35 in the slicer, then in the table I get only the records with number 31 to 35

 

I tried to use a new table where I typed in the values 5, 10, 15, 20, ... , 50 and use this for the slicer. And I added a filter where number should be less or equal the selected value in the slicer. The filter doesn't work: all records are shown.

 

How can I solve this problem?

 

Thanks

 

R.W.

  • Anonymous's avatar
    Anonymous
    7 years ago

    So to replicate your problem I have setup a table in power query that contains two columns, one with an Id column from 0 to 24 and another column with a random integer between 1 and 50 called values. Then I have created another table that just contains numbers between 5 and 50 in increments of 5. There are no relationships between these two tables.

     

    Then to get the result you require I have the following measure

     

     

    Values Filtered =
        IF (
            HASONEVALUE ( 'Filter Table'[Filter] ) && HASONEVALUE ( 'Table'[Id] ),
            CALCULATE (
                VALUES ( 'Table'[Value] ),
                FILTER ( ( 'Table' ), 'Table'[Value] <= VALUES ( 'Filter Table'[Filter] ) )
            ),
            BLANK ()
        )

    What it does is check if in the current context if there is only one value of Id, aka only one row of the Table is in the current context, and that there is only one value selected from the filter table. If either of these are false it will return blank, if you want some kind of aggregation it can be added.

     

     

    If the conditions are met then it will display the values that are less than or equal to the selected value of the fitler table.

     

    I hope this helps

     

  • Anonymous's avatar
    Anonymous
    7 years ago

    Anonymous,

    Yes if you use Anonymous's DAX. You can add an index column in Query Editor to represent ID.  




    Or you can change the DAX to the following ,for more details, please check attached PBIX file. It doesn't require Id column using this DAX.

    Measure = 
        IF (
            HASONEVALUE ( Parameter[Parameter] ) && HASONEVALUE ( 'Table1'[Value] ),
            CALCULATE (
                VALUES ( Table1[Value] ),
                FILTER ( ( 'Table1' ), Table1[Value] <= VALUES ( Parameter[Parameter] ) )
            ),
            BLANK ()
        )




    Regards,
    Lydia

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    So to replicate your problem I have setup a table in power query that contains two columns, one with an Id column from 0 to 24 and another column with a random integer between 1 and 50 called values. Then I have created another table that just contains numbers between 5 and 50 in increments of 5. There are no relationships between these two tables.

     

    Then to get the result you require I have the following measure

     

     

    Values Filtered =
        IF (
            HASONEVALUE ( 'Filter Table'[Filter] ) && HASONEVALUE ( 'Table'[Id] ),
            CALCULATE (
                VALUES ( 'Table'[Value] ),
                FILTER ( ( 'Table' ), 'Table'[Value] <= VALUES ( 'Filter Table'[Filter] ) )
            ),
            BLANK ()
        )

    What it does is check if in the current context if there is only one value of Id, aka only one row of the Table is in the current context, and that there is only one value selected from the filter table. If either of these are false it will return blank, if you want some kind of aggregation it can be added.

     

     

    If the conditions are met then it will display the values that are less than or equal to the selected value of the fitler table.

     

    I hope this helps

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thomas,

       

      Thanks.

       

      Is the ID necessary in this construction?

      In my table I don't have an ID.

       

      R.W.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Anonymous,

        Yes if you use Anonymous's DAX. You can add an index column in Query Editor to represent ID.  




        Or you can change the DAX to the following ,for more details, please check attached PBIX file. It doesn't require Id column using this DAX.

        Measure = 
            IF (
                HASONEVALUE ( Parameter[Parameter] ) && HASONEVALUE ( 'Table1'[Value] ),
                CALCULATE (
                    VALUES ( Table1[Value] ),
                    FILTER ( ( 'Table1' ), Table1[Value] <= VALUES ( Parameter[Parameter] ) )
                ),
                BLANK ()
            )




        Regards,
        Lydia