Skip to main content
Nov 23, 2021 2:13 AM UTC
Question

Ignore a dimension filter in a KPI calculation

Hi All,

 

I have a date dimension and a related KPI (Using Running_Total). What we'd like to be able to do is to filter the date dimension shown in the component (e.g Last 20 days), but still have the KPI calculation based on the full dataset (ie. ignore the date filter).

 

thanks

David

14 replies

Level 0
Nov 24, 2021 1:00 PM UTC

Hi @david.van.d11​ 

 

in order to ignore the filters, you need to use PU functions instead of regular aggregation.

It depends on your KPI how it will exactly look like, but you need something like this:

 

Dimension: PU_FIRST( DOMAIN_TABLE( ROUND_DAY("Table"."Date") ), ROUND_DAY("Table"."Date") )

KPI: RUNNING_SUM( PU_SUM( DOMAIN_TABLE( ROUND_DAY("Table"."Date") ), "Table"."Value" ), ORDER BY ( PU_FIRST( DOMAIN_TABLE( ROUND_DAY("Table"."Date") ), ROUND_DAY("Table"."Date") ) ASC ) )

 

 

In this example, the "Table"."Value" column is summed up as the KPI (marked bold), but this is depending on your actual KPI how you need to formulate this.

Note that you also have to use RUNNING_SUM instead of RUNNING_TOTAL, as RUNNING_TOTAL will again take the filters into account.

 

Best

David

Nov 25, 2021 5:44 AM UTC

Hi @david.van.d11​ 

 

in order to ignore the filters, you need to use PU functions instead of regular aggregation.

It depends on your KPI how it will exactly look like, but you need something like this:

 

Dimension: PU_FIRST( DOMAIN_TABLE( ROUND_DAY("Table"."Date") ), ROUND_DAY("Table"."Date") )

KPI: RUNNING_SUM( PU_SUM( DOMAIN_TABLE( ROUND_DAY("Table"."Date") ), "Table"."Value" ), ORDER BY ( PU_FIRST( DOMAIN_TABLE( ROUND_DAY("Table"."Date") ), ROUND_DAY("Table"."Date") ) ASC ) )

 

 

In this example, the "Table"."Value" column is summed up as the KPI (marked bold), but this is depending on your actual KPI how you need to formulate this.

Note that you also have to use RUNNING_SUM instead of RUNNING_TOTAL, as RUNNING_TOTAL will again take the filters into account.

 

Best

David

Thanks David.

 

Some really interesting techniques in your solution I would never have thought of. Thanks for responding in detail. I'll let this forum know how we go.

 

regards

David

Nov 26, 2021 6:09 AM UTC

Hi David,

 

Thanks, your suggested approach worked really well.

 

The double date field in the domain_table is a very cool trick I would never have thought of 😀. If my understanding is correct, this creates a CROSS JOIN with all possible date combinations.

 

thanks

David

Level 0
Nov 26, 2021 7:51 AM UTC

Hi David,

 

great to hear it worked!

 

Are you referring to PU_FIRST( DOMAIN_TABLE( ROUND_DAY("Table"."Date") ), ROUND_DAY("Table"."Date") )?

This is not calculating a Cross Join. In general, Cross Joins are not supported in PQL. What it simply does is, it retrieves the day value from the DOMAIN_TABLE (i.e. the "first" day for each day in the DOMAIN_TABLE is that day). So in fact, this does the opposite of a join - I use it to avoid any join. Because if I would use just the regular ROUND_DAY("Table"."Date") as a dimension, while using DOMAIN_TABLE in the KPI, this would introduce the join between the DOMAIN_TABLE and the "Table". Since they have a 1:N relationship, the values would "multiply", i.e. you would have the same day multiple times in your dimension, because there is no real aggregation function used. And you cannot use real aggregation functions, because they would take the filters into account ;)

 

Hope that helped understanding the query!

 

Best

David