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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Super User
Super User

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
Super User
Super User

@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
Super User
Super User

@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
Super User
Super User

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors