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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Filter function with time segment

Hello to all,

First of all here is my data table :

image.png

I would like to modify the "Filter" function of this measure :
Index_Arrets_Turbidity = RANKX(FILTER(ALL(fact_points_measures_faucon), fact_points_measures_faucon[id_measure_faucon]=370 && fact_points_measures_faucon[dt (1j)]>=DATE(2020,9, 1) && fact_points_measurements_faucon[dt (1d)]<=DATE(2020,12,1) ), CALCULATE(AVERAGE(fact_points_measurements_faucon[Index]),dim_measurements_faucon[group_measurement]="Turbidity"),,ASC,Skip)
I would like the values of DATE() not to be filled in manually but to be filled in automatically according to my time segment :

image.png
Thank you in advance

 

Joël

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @Anonymous 

Index_Arrets_Turbidity =
VAR min_ =
    MIN ( DateT[Date] )
VAR max_ =
    MAX ( DateT[Date] )
RETURN
    RANKX (
        FILTER (
            ALL ( fact_points_measures_faucon ),
            fact_points_measures_faucon[id_measure_faucon] = 370
                && fact_points_measures_faucon[dt (1j)] >= min_
                && fact_points_measurements_faucon[dt (1d)] <= max_
        ),
        CALCULATE (
            AVERAGE ( fact_points_measurements_faucon[Index] ),
            dim_measurements_faucon[group_measurement] = "Turbidity"
        ),
        ,
        ASC,
        SKIP
    )

where DateT[Date] is the field you are using in the slicer

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

6 REPLIES 6
AlB
Community Champion
Community Champion

@Anonymous 

You're not explaining what the expected result is and why, so I cannot check the result. In any case, it looks like youa renot following the pattern we developed earlier. You are seemingly ignoring the effects of context transition. Try:

Index_Arrets_Turbidity V2 = 
VAR firstDate_ = [First date]
VAR lastDate_ = [Last date]
RETURN
RANKX (
        FILTER (
            ALL ( fact_points_mesures_faucon ),
            fact_points_mesures_faucon[id_mesure_faucon] = 370
                && fact_points_mesures_faucon[dt (1j)] >= firstDate_
                && fact_points_mesures_faucon[dt (1j)] <= lastDate_
        ),
        CALCULATE (
            AVERAGE ( fact_points_mesures_faucon[Index] ),
            dim_mesure_faucon[groupement_mesure] ="Turbidité"
        ),
        ,
        ASC,
        SKIP
    )

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Anonymous
Not applicable

@AlB What I would like to have is a Ranks function that automatically recalculates itself according to the time segment.
Roughly the same result as this function:

image.png

image.png

But without using "ALLSELECTED" because this function truncates the result of the other measurements that are related to it.

Thanks for your help

 

Joël

AlB
Community Champion
Community Champion

@Anonymous 

I need more info.What exactly doesn't work?

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Anonymous
Not applicable

Hello @AlB 

The Ranks function continues to calculate on all dates without taking into account my min_ and max_ variables that I have integrated in my filter function. I shared my pbix so that it is more meaningful.

AlB
Community Champion
Community Champion

Hi @Anonymous 

Index_Arrets_Turbidity =
VAR min_ =
    MIN ( DateT[Date] )
VAR max_ =
    MAX ( DateT[Date] )
RETURN
    RANKX (
        FILTER (
            ALL ( fact_points_measures_faucon ),
            fact_points_measures_faucon[id_measure_faucon] = 370
                && fact_points_measures_faucon[dt (1j)] >= min_
                && fact_points_measurements_faucon[dt (1d)] <= max_
        ),
        CALCULATE (
            AVERAGE ( fact_points_measurements_faucon[Index] ),
            dim_measurements_faucon[group_measurement] = "Turbidity"
        ),
        ,
        ASC,
        SKIP
    )

where DateT[Date] is the field you are using in the slicer

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Anonymous
Not applicable

Hello @AlB 

I'll contact you again regarding the same problem because the solution you kindly wrote to me doesn't work anymore. To make it easier, I am attaching the PBIX in the following link : https://1drv.ms/u/s!Ao1OrcTeY008gYU2OOM2oBSrDBzgpQ?e=1uVQAg 

Thank you in advance for your help,

Joël

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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