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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
dgolovanova
Frequent Visitor

MIN value of a slicer based on a date in MM.YYYY format

Good afternoon,

Please help with advice.

There is a field in the DATE format, contains only the month and year (2.2021, 8.2023, etc.).

The client want to use a slicer in the "between" style (they don't like the extra Timeline slicer).

Power BI automatically displays dates in the format dd.mm.yyyy, which means that the table value of 8.2023 corresponds to the value of 1.8.2023.

I use the MIN and MAX functions to determine the minimum and maximum value of the slicer.

I need that if I select a date other than the first day of the month, the selected month will be returned to me, not the next one.

For example, for 5.12.2021, I need to get the value 1.12.2021 instead of 1.1.2022.

Is it possible?

Thank you in advance.

 

dgolovanova_0-1711359024313.jpeg

 

 

dgolovanova_1-1711359024316.jpeg

 

2 ACCEPTED SOLUTIONS

Hi,

In my opinion, if you want to use continuous date in the slicer, but if your fact table (sales table) date column is not continuous, please try using calenar dimension table, something like below.

Calendar = 
VAR _startdate =
    EOMONTH ( MIN ( Sales[Date] ), -1 ) + 1
VAR _enddate =
    EOMONTH ( MAX ( Sales[Date] ), 0 )
RETURN
    CALENDAR ( _startdate, _enddate )

Jihwan_Kim_1-1711686129778.png

 

 

Jihwan_Kim_0-1711686119715.png

 

Min date = 
VAR _selectedmonth =
    MONTH ( MIN ( 'Calendar'[Date] ) )
VAR _selectedyear =
    YEAR ( MIN ( 'Calendar'[Date] ) )
RETURN
    MINX (
        FILTER (
            Sales,
            YEAR ( Sales[Date] ) = _selectedyear
                && MONTH ( Sales[Date] ) = _selectedmonth
        ),
        Sales[Date]
    )

 

Max date = 
VAR _selectedmonth =
    MONTH ( MAX ( 'Calendar'[Date] ) )
VAR _selectedyear =
    YEAR ( MAX ( 'Calendar'[Date] ) )
RETURN
    MAXX(
        FILTER (
            Sales,
            YEAR ( Sales[Date] ) = _selectedyear
                && MONTH ( Sales[Date] ) = _selectedmonth
        ),
        Sales[Date]
    )

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

Good afternoon,
sorry for the late reply.

Everything works.

Thank you very much for help.
Regards

View solution in original post

6 REPLIES 6
dgolovanova
Frequent Visitor

Hello Jihwan,

Thanks for the reply, but this is not exactly what I need.
The problem is that my date field does not contain the day, only the month and year.
If I select the "Vertical List" slider type, the date is displayed the same way as in the table, i.e. in mm.yyyy format.

dgolovanova_0-1711444855371.png

But if you select the "Between" slider type, the date is displayed in the format dd.mm.yyyy.
And if you select a start date greater than the first day of the month, then the minimum value of the slicer already returns the next month, not the current month.
In the following example "Max date" is ok, but "Min date" should be 12.2021 instead of 01.2022.

dgolovanova_1-1711444884790.png

Can't attach the file 😞
Thanks again.
Regards

Hi,

Please provide your sample pbix file, and then I can try to look into it.

Please try using onedrive link or dropbox link to share the link of the sample file.

Thank you.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Hi,

In my opinion, if you want to use continuous date in the slicer, but if your fact table (sales table) date column is not continuous, please try using calenar dimension table, something like below.

Calendar = 
VAR _startdate =
    EOMONTH ( MIN ( Sales[Date] ), -1 ) + 1
VAR _enddate =
    EOMONTH ( MAX ( Sales[Date] ), 0 )
RETURN
    CALENDAR ( _startdate, _enddate )

Jihwan_Kim_1-1711686129778.png

 

 

Jihwan_Kim_0-1711686119715.png

 

Min date = 
VAR _selectedmonth =
    MONTH ( MIN ( 'Calendar'[Date] ) )
VAR _selectedyear =
    YEAR ( MIN ( 'Calendar'[Date] ) )
RETURN
    MINX (
        FILTER (
            Sales,
            YEAR ( Sales[Date] ) = _selectedyear
                && MONTH ( Sales[Date] ) = _selectedmonth
        ),
        Sales[Date]
    )

 

Max date = 
VAR _selectedmonth =
    MONTH ( MAX ( 'Calendar'[Date] ) )
VAR _selectedyear =
    YEAR ( MAX ( 'Calendar'[Date] ) )
RETURN
    MAXX(
        FILTER (
            Sales,
            YEAR ( Sales[Date] ) = _selectedyear
                && MONTH ( Sales[Date] ) = _selectedmonth
        ),
        Sales[Date]
    )

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Good afternoon,
sorry for the late reply.

Everything works.

Thank you very much for help.
Regards

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file whether it suits your requirement.

 

Jihwan_Kim_0-1711391912959.png

 

STARTOFMONTH function (DAX) - DAX | Microsoft Learn

 

Min Date start of month: = 
CALCULATETABLE (
    STARTOFMONTH ( 'Calendar'[Date] ),
    'Calendar'[Date] = MIN ( 'Calendar'[Date] )
)

 

Max Date start of month: = 
CALCULATETABLE (
    STARTOFMONTH ( 'Calendar'[Date] ),
    'Calendar'[Date] = MAX ( 'Calendar'[Date] )
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Top Kudoed Authors