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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
poko
Resolver I
Resolver I

How to calculate in measure for date picker selected year

Hello everyone,

 

I'm not sure if I'm my dax variable is correct but I need a year picker (slicer). I need date picker when a user pick a year it will calculate the picked year + 1 and the first day of the following year. Example it means when a user pick year 2021 , dax will return to the date 01/01/2022.

 

I created this one :

VAR SelectedYear = SELECTEDVALUE('Calendar'[Date].[Year])
VAR FirstDayOfNextYear = DATE(SelectedYear+1, 1, 1)
 
I'm not sure if it's correct because I don't get correct data . 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @poko 

Based on your needs, I have created the following table.

vjialongymsft_0-1731651855575.png

 

Using the formula you provided, the result will always return 1/1/1901.

vjialongymsft_1-1731651930276.png

 

You only need to make slight modifications to your Dax to achieve your needs:

M2 = 
var SelectedYear = YEAR(SELECTEDVALUE('Table'[Date]))
RETURN
 DATE(SelectedYear+1, 1, 1)

 

Result:

vjialongymsft_2-1731652021683.png

vjialongymsft_3-1731652033798.png

 

 

 

 

 

 

Best Regards,

Jayleny

 

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

8 REPLIES 8
Anonymous
Not applicable

Hi @poko 

Based on your needs, I have created the following table.

vjialongymsft_0-1731651855575.png

 

Using the formula you provided, the result will always return 1/1/1901.

vjialongymsft_1-1731651930276.png

 

You only need to make slight modifications to your Dax to achieve your needs:

M2 = 
var SelectedYear = YEAR(SELECTEDVALUE('Table'[Date]))
RETURN
 DATE(SelectedYear+1, 1, 1)

 

Result:

vjialongymsft_2-1731652021683.png

vjialongymsft_3-1731652033798.png

 

 

 

 

 

 

Best Regards,

Jayleny

 

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

Anonymous
Not applicable

Hi @poko 

Has your problem been resolved? If so, could you share your solution so that others with similar issues can benefit from it?

 


Best Regards,

Jayleny

vojtechsima
Super User
Super User

Hello, @poko 

this measure is essentially fine, depends what you wanna do with it.

I recommend using physical columns for Year (just for clarity) instead of Date.Year.

If you mark your calendar as Date Table, you should lose this option anyway.

 

then it depends on your exact measure what you wanna achieve.

 

you can have something like this:

Measure = 
var _year = SELECTEDVALUE('Calendar'[Year])+1
CALCULATE(
SUM('Table'[idk]),
'Calendar'[Year] = _year
)

my meausure should pick up values in first top row... with criteria mentioned below..
PendingCasesCount411 =
VAR SelectedYear = SELECTEDVALUE('Calendar'[Date].[Year])
VAR FirstDayOfNextYear = DATE(SelectedYear+1, 1, 1)
RETURN
    COUNTROWS(
        FILTER(
            CecCaseDetail,
            VAR TopEvent =
                TOPN(
                    1,
                    FILTER(
                        CecCaseEvent,
                        CecCaseEvent[CecCaseID] = CecCaseDetail[CaseID] &&
                        CecCaseEvent[ToStateOfProceedingID] <> CecCaseEvent[FromStateOfProceedingID] &&
                        CecCaseEvent[EventDate] < FirstDayOfNextYear
                    ),
                    CecCaseEvent[EventOrder],
                    DESC
                )
            VAR SopBeforeDate =
                IF(
                    NOT ISEMPTY(TopEvent),
                    SELECTCOLUMNS(TopEvent, "ToStateOfProceedingID", CecCaseEvent[ToStateOfProceedingID])
                )
            RETURN
                SopBeforeDate IN {2, 3, 4}
        )
    )
Angith_Nair
Continued Contributor
Continued Contributor

Hi @poko 

 

Use the below dax:

PendingCasesCount411 =
VAR SelectedYear = SELECTEDVALUE('Calendar'[Date].[Year])
VAR FirstDayOfNextYear = DATE(SelectedYear + 1, 1, 1)

RETURN
    COUNTROWS(
        FILTER(
            CecCaseDetail,
            VAR TopEvent =
                TOPN(
                    1,
                    FILTER(
                        CecCaseEvent,
                        CecCaseEvent[CecCaseID] = CecCaseDetail[CaseID] &&
                        CecCaseEvent[ToStateOfProceedingID] <> CecCaseEvent[FromStateOfProceedingID] &&
                        CecCaseEvent[EventDate] < FirstDayOfNextYear
                    ),
                    CecCaseEvent[EventOrder],
                    DESC
                )
            VAR SopBeforeDate =
                IF(
                    NOT ISEMPTY(TopEvent),
                    SELECTCOLUMNS(TopEvent, "ToStateOfProceedingID", CecCaseEvent[ToStateOfProceedingID])
                )
            RETURN
                SopBeforeDate IN {2, 3, 4}
        )
    )

@poko try adding ALL(CecCaseEvent) to the measure.

   FILTER(
                        ALL(CecCaseEvent),
                        CecCaseEvent[CecCaseID] = CecCaseDetail[CaseID] &&
                        CecCaseEvent[ToStateOfProceedingID] <> CecCaseEvent[FromStateOfProceedingID] &&
                        CecCaseEvent[EventDate] < FirstDayOfNextYear
                    )

 

btw you can send me sample file (post link from onedrive/google) and I can work on it directly.

sure I sent you email

I need data that will get all before 01/01/2022, sorry I mentioned it.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.