Forum Discussion

MTBERRY1029's avatar
MTBERRY1029
Regular Visitor
5 years ago
Solved

Performing TOPN on filtered table

Hello!

I am having a hard time finding the correct logic to use for an issue I have filtering a table. The table is a reference table with values  that change over time (i.e. electricity rates that change every few months). The goal of this script is to filter the reference table to a single row, which I will then reference for a calculated column. Here is the source data I am using:

UTILITYEFFECTIVE_DATERATESUMMER_CONSUMPTION_ON_PEAK
SCE6/1/21TOU-GS-3E0.50727
SCE6/1/21TOU-GS-3D0.13061
SCE6/1/21TOU-GS-2-E0.55612
SCE6/1/21TOU-GS-2-D0.13828
SCE6/1/21TOU-GS-1-D0.16903
SCE6/1/21TOU-GS-1-E0.4701
SCE6/1/21AL-2F0.0873
SCE6/1/21TOU-GS-3E-CPP0.50727
SCE6/1/21TOU-GS-3D-CPP0.13061
SCE6/1/21TOU-GS-2-E-CPP0.55612
SCE6/1/21TOU-GS-2-D-CPP0.13828
SCE6/1/21TOU-GS-1-D-CPP0.16903
SCE6/1/21TOU-GS-1-E-CPP0.4701
SCE2/1/21TOU-GS-3E0.50521
SCE2/1/21TOU-GS-3D0.12889
SCE2/1/21TOU-GS-2-E0.55352
SCE2/1/21TOU-GS-2-D0.13618
SCE2/1/21TOU-GS-1-D0.16687
SCE2/1/21TOU-GS-1-E0.4676
SCE2/1/21AL-2F0.08543
SCE2/1/21TOU-GS-3E-CPP0.50521
SCE2/1/21TOU-GS-3D-CPP0.12889
SCE2/1/21TOU-GS-2-E-CPP0.55352
SCE2/1/21TOU-GS-2-D-CPP0.13618
SCE2/1/21TOU-GS-1-D-CPP0.16687
SCE2/1/21TOU-GS-1-E-CPP0.4676
SCE10/1/20TOU-GS-3E0.48829
SCE10/1/20TOU-GS-3D0.12473
SCE10/1/20TOU-GS-2-E0.5405
SCE10/1/20TOU-GS-2-D0.13279
SCE10/1/20TOU-GS-1-D0.15859
SCE10/1/20TOU-GS-1-E0.44951
SCE10/1/20AL-2F0.08513

 

My confusion lies in finding a way to perform a TOPN function on an already filtered table. Any insight on how to "nest" a filtered table in a TOPN filter?

What I trying to accomplish:

1. Filter by RATE column

 

 

 

FILTER(Sheet1, Sheet1[RATE] = "TO-GS-2-D")

 

 

 


2. Filter EFFECTIVE_DATE using logical operator

 

 

 

FILTER(Sheet1, Sheet1[EFFECTIVE_DATE] < 'REFERENCE_DATE')

 

 

 

 

3. Return the the latest row 

 

 

 

TOPN(1,Sheet1, Sheet1[EFFECTIVE_DATE], DESC)

 

 

 

Looking to output the SUMMER_CONSUMPTION_ON_PEAK value as a measure.

 

Any insight is much appreciated!

6 Replies