Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
rafabg
Regular Visitor

get count of words based on user currently period selection

Hi,

What I need to do is get the top 10 words from a period prior than the currently selected one.

For ex: if the selected period is 5/5/2020 to 5/7/2020, I wanna check the top 10 count of words from 5/2/2020 to 5/4/2020.

 

I was trying to use CALCULATETABLE to filter the datetime columns using the max and min (selected) date as reference, but as I understand, this is not possible, cuz the CALCULETABLE does not work with context based filters (it returns the whole table).

 

Here is an example of the data:

worddate
atendimentos05/07/2020
explica05/07/2020
explica05/05/2020
municipios05/06/2020
numeros05/05/2020
municipios05/05/2020
atendimentos05/05/2020
municipios05/05/2020
numeros05/04/2020
atendimentos05/04/2020
atendimentos05/02/2020
explica05/03/2020
numeros05/02/2020
numeros05/02/2020
explica05/02/2020
explica05/04/2020
atendimentos05/04/2020

 

The currenctly is:

05/05 to 05/07/2020
municipios3
explica2
atendimentos2
numeros1

 

The result I want is:

05/02 to 05/04/2020
atendimentos3
explica3
numeros3

 

I was trying to make a table with rows from 1 to 10 (n), and using this formula:

CALCULATE(FIRSTNONBLANK([word],0),SAMPLE(1,TOPN(SELECTEDVALUE(n),CALCULATETABLE(SUMMARIZE(words,word,"qnt",COUNTA([word])),[date]>=priorDateStart,[date]<=priorDateEnd),[qnt],DESC),[qnt],ASC))

 

Is there a way to make this to work, considering that it must be dynamic?

Thanks!

 

 

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @rafabg ,

 

Sorry, the previous reply ignored some conditions. This should meet your needs:

 

1. Create a calendar table.

Calendar =
CALENDAR ( MIN ( 'Table'[date] ), MAX ( 'Table'[date] ) )

 

2. Create Measures.

Count = 
VAR maxdate =
    CALCULATE ( MAX ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar'[Date] ) )
VAR mindate =
    CALCULATE ( MIN ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar'[Date] ) )
VAR days =
    DATEDIFF ( mindate, maxdate, DAY )
VAR previousmaxdate = maxdate - days - 1
VAR previousmindate = mindate - days - 1
VAR table1 =
    FILTER ( 'Table', [date] <= previousmaxdate && [date] >= previousmindate )
RETURN
    COUNTROWS ( table1 )
Top10Count = 
CALCULATE (
    [Count],
    FILTER (
        VALUES ( 'Table'[word] ),
        IF ( RANKX ( ALL ( 'Table'[word] ), [Count],, DESC ) <= 10, [Count], BLANK () )
    )
)

 

3. The result is as follows. The slicer is created with Date column in Calendar table.

result3.png

 

You can check more details from here.

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Icey
Community Support
Community Support

Hi @rafabg ,

 

Sorry, the previous reply ignored some conditions. This should meet your needs:

 

1. Create a calendar table.

Calendar =
CALENDAR ( MIN ( 'Table'[date] ), MAX ( 'Table'[date] ) )

 

2. Create Measures.

Count = 
VAR maxdate =
    CALCULATE ( MAX ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar'[Date] ) )
VAR mindate =
    CALCULATE ( MIN ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar'[Date] ) )
VAR days =
    DATEDIFF ( mindate, maxdate, DAY )
VAR previousmaxdate = maxdate - days - 1
VAR previousmindate = mindate - days - 1
VAR table1 =
    FILTER ( 'Table', [date] <= previousmaxdate && [date] >= previousmindate )
RETURN
    COUNTROWS ( table1 )
Top10Count = 
CALCULATE (
    [Count],
    FILTER (
        VALUES ( 'Table'[word] ),
        IF ( RANKX ( ALL ( 'Table'[word] ), [Count],, DESC ) <= 10, [Count], BLANK () )
    )
)

 

3. The result is as follows. The slicer is created with Date column in Calendar table.

result3.png

 

You can check more details from here.

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Icey
Community Support
Community Support

Hi @rafabg ,

 

Please kindly check if the attachment is what you want.

RANGE.PNG

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

FrankAT
Community Champion
Community Champion

Hi @rafabg 

is that whar you are looking for?

 

14-08-_2020_00-38-00.png

 

Regards FrankAT

@FrankAT  Hello, no, I would like to show the past period, based on currently selection...the main problem, as I see it, is that the period is not regular, it can be 1, 2, 3, 4 days, and so on...

If the user select a range of 7 days, for example, I wanna return the top 10 count of words from the previous period (7 days before the selected range).

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.