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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
aj1107
Helper I
Helper I

Passing Slicer Selection value in DAX Filter

I've a requirement to diplay last 6month (in X-axis) for a given month selected in Slicer. 

As a 1st step, I can get the 6month by restricting directly in DAX.

 

=calculate(count(column),filter(table1,cdate>=eomonth(today(),-6) && cdate<=eomonth(today(),-1)))

 

Above DAX by default diaplay 6month data in chart. Next step, i need to get the value from selected value from slicer. Slicer will have MMMYY value. Eg., if I select Apr17 in slicer, then the chart should display from Oct16 to Mar17.

 

Can anyone guide me on how to pass the selected month slicer value to underline DAX part.

 

Thank You.

16 REPLIES 16
Sravanisrinivas
New Member

Hi,
how to select by default last five years data in slicer...
for ex if i am selecting 2020 in my slicer, by default i want to show 2016-2020 data.
can you please provide me the dax code.

Hi,

See if my solution here helps - Flex a Pivot Table to show data for x months ended a certain user defined month.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Sravanisrinivas_0-1649164137910.png

Hi,
in my slicer i selected 2022, but my requirement is when i select 2022 need to show 2018-2022 data in my trend visuals...what is the dax code r how slove slove this issue.

 

if i select 2021,need 2017 to 2021 data

Hi @Sravanisrinivas ,

 

Do you want to show the default values on the slicer of the last 5 years or your calculations should be the ones in the last 5 years?

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



aamer
Regular Visitor

I have a similar issue..

I have TableA with transactional data, when filtered to get rows that belong to a specific year I used the following

MEASURE: SelectedYear = selectedvalue(Years[year]) // returns the correct selected year in a slicer

NewTable = Filter(TableA, Year(TransDate) = SelectedYear)

it returns an empty table with no rows

If I do a hardcode filter like the following it works fine

NewTable - Filter(TableA, Year(TransDate) = 2019)

I do not know what went wrong.

Hi @aamer ,

 

You cannot use measures to create tables in DAX measure are based on context and when you pickpup the SELECTEDVALUE on a table the value you get return is a table of multiple values so nothing is returned in your new table.

 

What is the purpose that you want to achieve?

 

Why are you creating a new table?


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thanks Felix for your reply.

I need to count the number of transactions per customer every year, then based on the selected year, we use the count of that year and the 2 previous years to determine certain status for the customer. So year selection must be dynamic and based on a slicer. Transaction count will be stored in a column (3 columns actually) for the selected year and the 2 prevoius ones.

In the calculated column, I use the following

TransSelectedYear = calculate( DISTINCTCOUNT (Revenue_Lines[TRX_NUMBER]), filter(Revenue_Lines, Revenue_Lines[TRX_Year] = [SelectedYear]))
 
My other solution is to get the TransactionCount explicitly per year (that works), then go through a huge decision structure statement to select the proper columns based on the year selection (should work but not tested yet), which I am trying to avoid.

Hi @aamer ,

 

This can be done using measures.

 

I don't know how your data is structure but I assume is something similar to the one below:

Date

Tranx_NUMBER

Column1

Column2

....

ColumnN

 

If you have a calendar table then you can add a measure for curent year and the previous 2 year that way you would be abble to make the count and further calculations.

 

Measures would be similar to this:

TransSelectedYear = DISTINCTCOUNT (Revenue_Lines[TRX_NUMBER])

TransSelectedYear - 1 = VAR Year_Selection = SELECTEDVALUE(DAte[Year])
Return
CALCULATE([TransselectedYear], FILTER(ALL(Date[Year]), Date[Year )= Year_Selection - 1]))

TransSelectedYear - 2 = VAR Year_Selection = SELECTEDVALUE(DAte[Year])
Return
CALCULATE([TransselectedYear], FILTER(ALL(Date[Year]), Date[Year )= Year_Selection - 2]))

 

Now this measures can be used to make the calculations.

 

If you share a sample data I can provide a better example.

 

No need to create additional tables on your model except the date table.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Felix - this is the correct way to do it. I was stumped on this also as intuitively you would be expected to work with the selected value expression directly. Passing in into a variable is the way to solve this. Much appreicated!

 

Thanks again for your reply..

I need the calculated table to group the transactions per customer. A measure will only calculate the transactions for the selected customer but if I need to do it for all customers I bleieve it has to be in a calculated column. This way I would be able to plot transaction count per customer.

My first step was to summarize the transactions table as follows:

 
CustomerTransactionsCount = SUMMARIZECOLUMNS(Revenue_Lines[Customers])
 
Then I would add the calculated columns.
Is there another way to do this calculations?
v-jiascu-msft
Microsoft Employee
Microsoft Employee

@aj1107

 

Hi,

 

Did you solve your problem? What else can I do for you?

 

Best Regards!

Dale

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

Hi,

 

Is it possible when there is no relationship between two table?

 

Thanks in Advance!

Jaymin

MFelix
Super User
Super User

Hi @aj1107,

 

I don't know what is the column you are using on your slicer but assuming its column CDATE and you only have one single value select on the slicer you can use this formula:

 

Date_selected = Max(Table1(CDATE))

 

Regards,

MFelix

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thanks for the reply.
I tried the soultion but not getting the expected result.  
 
Slicer : cdate
calcmeasure1 : Date_selected=max(cdate)
calcmeasuer2 : idcount=calculate(count(id),filter(table,cdate>=date_selected)
 
id, plan, cdate
1, ab, 4/30/2017
2, wr, 3/31/2017
3, qw, 2/28/2017
4, we, 3/31/2017
 
When i select slicer, it gives count only for the selected date and not for the filter range.
 
4/30/2017 - 1
3/31/2017 -2
2/28/2017 - 1

Expected result
 
4/30/2017 - 1
3/31/2017 -3
2/28/2017 - 4
 
Not sure am I missing anything.

@aj1107

 

Hi,

 

Maybe you want the dates less than the selected date in the first post while you change it in the last post. This won’t be problem, just something about the operator. According to last post, you can try this formula.

IDCountNew =

IF (

    MAX ( Test[cdate] ) < MAX ( ForSlicer[cdate] ),

    BLANK (),

    CALCULATE (

        COUNT ( Test[id] ),

        FILTER (

            ALL ( Test ),

            Test[cdate] >= MAX ( ForSlicer[cdate] )

                && Test[cdate] >= MAX ( Test[cdate] )

        )

    )

)

 

Passing Slicer Selection value in DAX Filter.JPG 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Best Regards!

Dale

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.