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
skrempp
Frequent Visitor

Using slicer in measure returns no data

I am having an issue trying to use a value from a slicer as a filter for a measure.

 

I have a slicer that displays YearQtr.  When the user selects a YearQtr I want to use the corresponding NumQtr as a filter in a measure.  

 

SelectedQuarter = If (ISFILTERED(Opportunity[YearQtr]), MIN(Opportunity[NumQtrs]), 0) 

 

This formula returns a single value that I would like to use in a measure to as part of a calculation.  I have put SelectedQuarter in a card visual to make sure the value I'm expecting is returned.  

 

I then created a measure to use this SelectedQuarter slicer.  When I do this there are no results, just blank.  I can change the reference to [SelectedQuarter] in the measure to a hard coded number and the data appears.  I tried this multiple ways, two examples are below.   

 

QtrWeight = CALCULATE(SUM(Opportunity[Weight]),FILTER(Opportunity,Opportunity[NumQtrs] = [SelectedQuarter]+1))

 

QtrWeight = CALCULATE(SUM(Opportunity[Weight]),FILTER(Opportunity,Opportunity[NumQtrs] = IF(ISFILTERED(Opportunity[YearQtr]),Opportunity[NumQtrs]+1,1)))

 

I have spent hours trying to figure out where I went wrong.  Any help the community can give me will be greatly appriciated.

1 ACCEPTED SOLUTION

Hi @skrempp,

 

Since you add Opportunity[YearQtr] into slicer and sum Opportunity[Weight] based on slicer, when you select any value from slicer, for example, YearQtr=Quarter1, it will automatically filter table 'Opportunity', so, in current context, the 'Opportunity' table only contains records where YearQtr=Quarter1, in other words, NumQtrs=1. In that case, when you use [SelectedQuarter]+1(NumQtrs=2), it will return blank.

 

To resolve this problem, you need to create an extra table like below, add [YearQtr] from this table to slicer.

Quarter Table =
ADDCOLUMNS (
    VALUES ( Opportunity[YearQtr] ),
    "QuarterNum", LOOKUPVALUE ( Opportunity[NumQtr], Opportunity[YearQtr], [YearQtr] )
)

6.PNG

 

Then, make a little modification to your measure formula.

SelectedQuarter = If (ISFILTERED('Quarter Table'[YearQtr]), MIN('Quarter Table'[QuarterNum]), 0) 

QtrWeight = CALCULATE(SUM(Opportunity[Weight]),FILTER(Opportunity,Opportunity[NumQtr] = [SelectedQuarter]+1))

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
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
v-yulgu-msft
Employee
Employee

Hi @skrempp,

 

From the DAX formula, it seems there is nothing wrong with its syntax. You said the measure returned blank, did it show blank in table or chart visual? What about adding it in a card visual? You said it could return desired result if replacing the measure [SelectedQuarter] with hard coded number, right? Please check whether the values returned by [SelectedQuarter] are exactly matched with Opportunity[NumQtrs].

 

Since I was not able to reproduce your issue without any sample data, please share detailed data for test and provide screenshot of current result you have got.

 

Regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I will pull some sample data and post in the next few hours.  I spent several more hours playing with this yesterday and I figured out if I remove the '+1' the formula works.  I get the data for the quarter selected.  I am displaying the data in a table and some columns display data for the quarter the user selects and then other columns like the one I have posted my DAX for are pulling data for the quarter before the one the user selects or a range of quarters based on the one the user sets.  

 

I guess my questions now is why would the +1 cause this query to fail? I know the value returned by [SelectedQuarter] is a number.  I have a card visual displaying [SelectedQuarter] + 1 to test to make sure it is returning the right value and it is correct.  I have also used VALUE([SelectedQuarter])+1 in my formulat to make sure that [SelectedQuarter] is returning as a number and not text.  I verified Opportunity[NumQtrs] is an int.

Hi @skrempp,

 

Since you add Opportunity[YearQtr] into slicer and sum Opportunity[Weight] based on slicer, when you select any value from slicer, for example, YearQtr=Quarter1, it will automatically filter table 'Opportunity', so, in current context, the 'Opportunity' table only contains records where YearQtr=Quarter1, in other words, NumQtrs=1. In that case, when you use [SelectedQuarter]+1(NumQtrs=2), it will return blank.

 

To resolve this problem, you need to create an extra table like below, add [YearQtr] from this table to slicer.

Quarter Table =
ADDCOLUMNS (
    VALUES ( Opportunity[YearQtr] ),
    "QuarterNum", LOOKUPVALUE ( Opportunity[NumQtr], Opportunity[YearQtr], [YearQtr] )
)

6.PNG

 

Then, make a little modification to your measure formula.

SelectedQuarter = If (ISFILTERED('Quarter Table'[YearQtr]), MIN('Quarter Table'[QuarterNum]), 0) 

QtrWeight = CALCULATE(SUM(Opportunity[Weight]),FILTER(Opportunity,Opportunity[NumQtr] = [SelectedQuarter]+1))

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you @v-yulgu-msft!

 

This did it.  I had something similar to this several times and it did not work.  I must have had a reference wrong, but it worked this morning.

 

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.