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 in a measure

Hello, 

I don´t know if this is possible or if there is another possible solution for this:

 

Context:

  • I have a DB with all the dates of the steps in the sales funnel.
  • I want to create a funnel with the daily sales - I want to see what happened on the day that I select. 
  • "AND NOW" I want to compare different years in every step.

     

    This is how I have it now:

    Dulce_Gamez4_0-1643731359756.png

    Dulce_Gamez4_1-1643731596941.png

    Dulce_Gamez4_4-1643732760160.png

     

    e.g.

    Leads_2021 =
    VAR a = CALCULATE(DISTINCTCOUNT(Leads[ID_LEAD_SF]),FILTER(Preinscripciones,[EsLead]=1),'Date'[Year]=2021, USERELATIONSHIP('Date'[Date],Leads[F_ORIGEN_LEAD]))
    RETURN IF(ISBLANK(a),0,a)

    Dulce_Gamez4_5-1643732944602.png

     

    Leads_2022 =
    VAR a = CALCULATE(DISTINCTCOUNT(Leads[ID_LEAD_SF]),FILTER(Preinscripciones,[EsLead]=1),'Date'[Year]=2022, USERELATIONSHIP('Date'[Date],Leads[F_ORIGEN_LEAD]))
    RETURN IF(ISBLANK(a),0,a)

    Dulce_Gamez4_6-1643733031762.png

     

    EsLead =
    VAR a = MAX(Leads[F_ORIGEN_LEAD])
    RETURN IF(ISBLANK(a),0,1)

    Dulce_Gamez4_7-1643733048240.png

     

     

    • "AND NOW" I want to compare different years (but in an independent way  2019 vs 2022, 2021 vs 2022, etc..).

      I was thinking of putting two slices each one with the year that the person wants to compare, creating a measure with that value, and putting that measure in the measure of the steps. 

       

      So instead of  the measure "Leads_2021" would be -> "Leads_year1" and "Leads_2022" like ->Leads_year2"

       

      I tried but it doesn't work or maybe I don't know the right way to make it work. 

       

      ¿How can I create a measure with the value of the year that I selected in one of the two slicers so I can put it in the measure "Leads_year1" =? 

      Dulce_Gamez4_11-1643734330982.png

       

       

      Year1 = VALUES('Date'[Year])

      Dulce_Gamez4_12-1643734378447.png

       

       

      Leads_year1 =
      VAR a = CALCULATE(DISTINCTCOUNT(Leads[ID_LEAD_SF]),FILTER(Preinscripciones,[EsLead]=1),FILTER('Date','Date'[Year]=[Year1]), USERELATIONSHIP('Date'[Date],Leads[F_ORIGEN_LEAD]))
      RETURN IF(ISBLANK(a),0,a)

      Dulce_Gamez4_13-1643734410780.png

       

       

       

      Thank you in advance.

       

1 ACCEPTED SOLUTION
CerebusBI
Resolver I
Resolver I

Hi @Anonymous ,

 

Nice work!

 

It looks like you are looking for SELECTEDVALUE( table[column] ).

 

This function returns the value of the 'column', IF exactle on value is selected in the filter context.

 

The complete solution could have the following elements:

 

A. Two tables with years - one for year1 and another for year2. Lets call them 'Years1' and 'Years2', respectively. Each have one column 'Year'.

B. Two slicers: One for each of the tables. Both slicers shoud be configured to enforce single select.

C. Two measures to evaluate which year is selected.

 

Measure 1 =
IF( HASONEVALUE ( Years1 [Year] ),

SELECTEDVALUE ( Years1 [Year]),
"Error"
)
 
Measure 2 ist the same, but with the table Years2.
 
The IF-Condition with HASONEVALUE is not strictly necessary, if you enforce a single select through the slicers, but it's good practice if you want to use the measures in other contexts too.
 
I hope that's what you need.
 
Kind regards

 

 

View solution in original post

4 REPLIES 4
CerebusBI
Resolver I
Resolver I

Phew, for a moment I was worried. 😉

I'm glad that it works now. 👍

CerebusBI
Resolver I
Resolver I

Hi @Anonymous ,

 

Nice work!

 

It looks like you are looking for SELECTEDVALUE( table[column] ).

 

This function returns the value of the 'column', IF exactle on value is selected in the filter context.

 

The complete solution could have the following elements:

 

A. Two tables with years - one for year1 and another for year2. Lets call them 'Years1' and 'Years2', respectively. Each have one column 'Year'.

B. Two slicers: One for each of the tables. Both slicers shoud be configured to enforce single select.

C. Two measures to evaluate which year is selected.

 

Measure 1 =
IF( HASONEVALUE ( Years1 [Year] ),

SELECTEDVALUE ( Years1 [Year]),
"Error"
)
 
Measure 2 ist the same, but with the table Years2.
 
The IF-Condition with HASONEVALUE is not strictly necessary, if you enforce a single select through the slicers, but it's good practice if you want to use the measures in other contexts too.
 
I hope that's what you need.
 
Kind regards

 

 

Anonymous
Not applicable

Thank you for your answer CerebusBI 

 

It seems to work for the overall total 😊, but I don't know why when I put that measure in the matrix it doesn't work for the subcategories 😥.

Dulce_Gamez4_0-1643797434242.png

Dulce_Gamez4_1-1643797572300.png

Dulce_Gamez4_3-1643797745077.png

 

I don't have any relationship with the two tables that I have created (because I just want the value of the year to filter -> FILTER('Date','Date'[Year]=[Measure 1]), I thought it was that but when I create the relationship the numbers in the matrix are wrong... 

 

Dulce_Gamez4_2-1643797649267.png

Dulce_Gamez4_4-1643797952953.png

 

Do you think is there something about the relationships?

 

Kind regards,

Dulce

 

Anonymous
Not applicable

Sorry, I saw the mistake, it was the "edit interactions"... That I had changed before. But now it works :).

 

Thank you very much. 

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.