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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
pavithra12
Regular Visitor

dynamic table filter using slicer selection

Here is my case,

 

I have three tables, crop_year,division and totals.Capture.PNG

 

Totals is filtered based on crop_year and division. Divion is filtered based on crop_year, but as you can see due to circular dependency I am not able to establish a relationship between crop_year and division.

 

So, in order to filter the division based on the selected crop_year (for example 2017 has a different set of division and 2017 has a different set), I created a measure called as 'CropYear_Sel' in the crop_year table to capture the dynamic value selected by the user.

 

CropYear_Sel = var selection = SELECTEDVALUE(Crop_Year[CROP_YEAR],0000) return selection

 

And I wanted to use this measure to dynamically filter the division values, but when using the measure the result is null

 

CALCULATETABLE( DISTINCT( Division[DIVISION] ), FILTER( Division, Division[CROP_YEAR] = Crop_Year[CropYear_Sel] ) )

 

But, when the crop_year is hard coded I am able to get the filtered divisions using the below mentioned DAX

 

CALCULATETABLE(DISTINCT(Division[DIVISION]), Division[CROP_YEAR] = 2017)

 

Is there a solution for this? Any help would be appriciated! Thanks!

9 REPLIES 9
pavithra12
Regular Visitor

Here is my case,

 

I have three tables, crop_year,division and totals. 

Capture.PNG

 

Totals is filtered based on crop_year and division. Divion is filtered based on crop_year, but as you can see due to circular dependency I am not able to establish a relationship between crop_year and division.

 

So, in order to filter the division based on the selected crop_year (for example 2017 has a different set of division and 2017 has a different set), I created a measure called as 'CropYear_Sel' in the crop_year table to capture the dynamic value selected by the user.

 

CropYear_Sel = var selection = SELECTEDVALUE(Crop_Year[CROP_YEAR],0000) return selection

 

And I wanted to use this measure to dynamically filter the division values, but when using the measure the result is null

 

CALCULATETABLE( DISTINCT( Division[DIVISION] ), FILTER( Division, Division[CROP_YEAR] = Crop_Year[CropYear_Sel] ) )

 

But, when the crop_year is hard coded I am able to get the filtered divisions using the below mentioned DAX

 

CALCULATETABLE(DISTINCT(Division[DIVISION]), Division[CROP_YEAR] = 2017)

 

Is there a solution for this? Any help would be appriciated! Thanks!

Greg_Deckler
Community Champion
Community Champion

Just a guess, perhaps try:

 

CALCULATETABLE( DISTINCT( Division[DIVISION] ), FILTER( ALL(Division), Division[CROP_YEAR] = Crop_Year[CropYear_Sel] ) )



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi Greg!

 

Thanks for the reply, but that doesn't work either. 

 

I am quite not sure if I can create a dynamic calculate table or calculate column depending on user selections. The DAX function with a hard coded value if working fine but when using the measure it does not return data.

 

 

Can you provide some sample data? Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

This is the crop_year table,

Crop_Year.PNG

 

This is Totals table,

Totals.PNG

 

 

And this is the division table:

Division2.PNG

 

As you can see, division '2-central Divsion' is available only for the crop_years 2014,2015 and 2016. So If I select the crop_year as 2017 from the slicer, the totals value (second image)  for 2017 should be displayed in a table and the division for 2017 should be displayed in a seperate table (that is 2-central Divsion' should not be displayed under division).

 

Is there a way in which I can achive this? 

I'm actually not seeing whatever images? you posted. Can you post some text so that it can be copied and pasted into a data model and then experimented upon?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Crop_Year table:

2015

2016

2017

2018

 

Totals table

2016    11    49   819   AL   2250

2017    11    49   819   PA   2250

2017    11    49   819   HP   2250

2018    11    49   819   HP   2250

2015    11    49   819   CM   2250

 

Division Table

2-Cental Division     2014

2-Cental Division     2015

2-Cental Division     2016

1-Mid Division         2017

 

So when crop_year 2017 is selected from the slicer (using crop_year table),

The totals table should display the 2017 data (2nd and 3rd row) and even the division table should display the 2017 data (4th row).

 

Thanks! 

 

Hi Pavithra

 

I saw your post ... were you able to solve this issue?

I have landed up in same bucket now. 

Anonymous
Not applicable

I have a similar problem. when I try to use a measure as an argument to the filter function, it does not give any results. It will not be a valid argument then?

Helpful resources

Announcements
FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.