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
Syndicate_Admin
Administrator
Administrator

Setting a default value in a slicer

good morning, I currently have a report that contains 2 slicer, one associated with years and another with months, I want to leave pordefecto every time it is opened and report are selected automatically

1 ACCEPTED SOLUTION
v-chenwuz-msft
Community Support
Community Support

Hi @Syndicate_Admin ,

 

Maybe you can try the function ISFILTERED().

IF no selection, then get MONTH of TODAY() and use CALCULATE() to sum the value of this month.

You can refer the following expression:

Total =
VAR _today =
    TODAY()
VAR _Defult =
    CALCULATE(
        SUM( 'DATE'[Value] ),
        FILTER( ALL( 'DATE' ), MONTH( [DATE] ) = MONTH( TODAY() ) )
    )
RETURN
    IF( ISFILTERED( 'DATE'[Month] ), SUM( 'DATE'[Value] ), _Defult )

The result:

vchenwuzmsft_0-1637917576848.png

 

I put the pbix file in the end you can refer.


Best Regards

Community Support Team _ chenwu zhu

 

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

6 REPLIES 6
v-chenwuz-msft
Community Support
Community Support

Hi @Syndicate_Admin ,

 

Maybe you can try the function ISFILTERED().

IF no selection, then get MONTH of TODAY() and use CALCULATE() to sum the value of this month.

You can refer the following expression:

Total =
VAR _today =
    TODAY()
VAR _Defult =
    CALCULATE(
        SUM( 'DATE'[Value] ),
        FILTER( ALL( 'DATE' ), MONTH( [DATE] ) = MONTH( TODAY() ) )
    )
RETURN
    IF( ISFILTERED( 'DATE'[Month] ), SUM( 'DATE'[Value] ), _Defult )

The result:

vchenwuzmsft_0-1637917576848.png

 

I put the pbix file in the end you can refer.


Best Regards

Community Support Team _ chenwu zhu

 

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

 

AllisonKennedy
Super User
Super User

@mancemo You can select a value in the slicers and they will be the same values you see each time you open the report. 

 

Can you provide more detail on what you need though? Do you want the month to be dynamic and always default to current month? You may find Relative Date slicer more helpful than separate month and year slicers: 

https://docs.microsoft.com/en-us/power-bi/visuals/desktop-slicer-filter-date-range 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

hello, what I want is that when the report is opened the slicers that are showing date and year are default to the current feha and update the values of the report

the panel is this

mancemo_0-1637762681687.png

and that when it opens automatically, year and month are selected to update the other indicators

@mancemo 

 

It's not possible to set the default of your current slicer layout to current month. You could create a calculated column in Power Query that for example for this month of November would have the values: 

Jan

Feb

Mar

Apr

May

Jun

Jul

Aug

Sep

Oct

Current

Dec

 

And do the same for the Year. That way you could set the default value of both slicers to 'Current' and then the use can choose a different month if they desire. 

 

To do this, click Transform Data to open Power Query.

 

Click Add Column tab in the ribbon, then click Custom Column and use this code: 

 

if [Month name] = Date.MonthName(DateTime.LocalNow()) then "Current" else [Month name]

 

 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

hello thanks, I tell you a little that the date table I get from the following query

DATE = CALENDAR (DATE (2020, 1, 1), DATE (2021, 12, 31))
try so
my = IF [DATE[Date].MONTH] = Date.MonthName(DateTime.LocalNow()) then "Current" else [[DATE[Date].MONTH])
and it makes me an error

@mancemo 

 

Sorry for not being clear - the formula I gave is M (not DAX) so you need to click Transform Data to add this in Power Query. Since your Date table uses DAX, you will need to create the Date table in Power Query to use this method: https://excelwithallison.blogspot.com/2020/04/dimdate-what-why-and-how.html 

 

Alternative option is to use DAX to create the column, but it's less efficient. 

New Column = 

VAR _CurrentMonth = MONTH(TODAY())

RETURN
IF( _CurrentMonth = Date[Month], "Current", Date[Month])


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

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.