Forum Discussion

annag815's avatar
annag815
Frequent Visitor
6 years ago
Solved

Returning a table with calculated Top N

Hi everyone, 

 

I have created a new table with a new column "Rand": 

TableWithRand =
ADDCOLUMNS ( "Table1", "Rand", RAND() )
 
Originally I also added the following: 
VAR SampleSize = 10
VAR SampleSize5=  .05 *( COUNTROWS(TableWithRand)
VAR MySampleSize = IF(SampleSize5 > 10, SampleSize5, SampleSize)
RETURN
TOPN(MySampleSize, TableWithRand, [Rand])
 
However I now have to filter the table by date through a slicer and determine the sample size based on the filtered results. How can I achieve the result of the code above after the new table has been created and the user has selected the date range? 
 
 
  • Anonymous's avatar
    Anonymous
    6 years ago

    HI annag815 ,

     

    Tables in PBI are STATIC. ALWAYS. They're recalculated when data is refreshed. Table variables used in measures are dynamic but they are gone as soon as the measure has returned its value.

     

    Slicers cannot be used in Tables.  They can, however, be used in measures.

    Slicers are Filters,  use filter context.  Filters can change dynamically based on what is selected, and how filter interactions are defined.  Since measures are dynamic fields calculated on demand, they can leverage this filter context to shape results.

    Tables are populated once at data refresh, and don't update again.  If you change interactions, change slicers, the underlying row context and any calculations performed at load would be unaffected.

     

     

    Regards,

    Harsh Nathani

    Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

     

     

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    HI annag815 ,

     

    Tables in PBI are STATIC. ALWAYS. They're recalculated when data is refreshed. Table variables used in measures are dynamic but they are gone as soon as the measure has returned its value.

     

    Slicers cannot be used in Tables.  They can, however, be used in measures.

    Slicers are Filters,  use filter context.  Filters can change dynamically based on what is selected, and how filter interactions are defined.  Since measures are dynamic fields calculated on demand, they can leverage this filter context to shape results.

    Tables are populated once at data refresh, and don't update again.  If you change interactions, change slicers, the underlying row context and any calculations performed at load would be unaffected.

     

     

    Regards,

    Harsh Nathani

    Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

     

     

  • v-lili6-msft's avatar
    v-lili6-msft
    Icon for Community Support rankCommunity Support

    hi  annag815 

    First, you should know that:

    1. Calculation column/table(new column/new table) not support dynamic changed based on filter or slicer.
    2. Measure can be affected by filter/slicer, so you can use it to get dynamic summary result in a visual by its row context.

    https://www.sqlbi.com/articles/calculated-columns-and-measures-in-dax/

     

    Second, since slicer is just a visual in report that use field from one table, so it couldn't affect the basic table or other tables any more, you could create a meausre and use it in visual level filetr to filter a table visual by slicer.

     

    Regards,

    Lin