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
ramk
Regular Visitor

YTD as dynamic value using DAX

HI,

 

I am looking to make the YTD measure to be dynamic based on a input parameter.
This input parameter then will be used a slicer in power pivot.

 

For ex:
To calculate YTD, we use :


IsYTD = IF( YEAR(Calendar[DateSK]) = YEAR(TODAY()) && Calendar[DateSK]<TODAY(),1,0)

 

But above TODAY() is hardcoded and I am trying to make it dynamic so that YTD is calculateed based on users preference
Looking for more a function like feature in M.

 

something like :

 

VAR pickdate = date(2018,2,1) -- pickdate to be a slicer
IsYTD = IF( YEAR(Calendar[DateSK]) = YEAR(pickdate) && Calendar[DateSK]<pickdate,1,0)

 

I tried to create a new datetable and reference it in above query by joining the relationship with Calendar table but it doesnt seem to calculate YTD dynamically.

1 ACCEPTED SOLUTION
Salonic
Resolver I
Resolver I

Hello,

 

By using a WhatIf parameter, you may let the users choose their parameters dynamically.

 

I created a simple table :

001.png

 

I then created a WhatIf parameter :

LastDays = GENERATESERIES(0; 50; 1)

002.png

 

Inside the data table, I added 3 new measures :

Date Min = DATE(YEAR(TODAY()-LastDays[Last DAys Val]);1;1)
Date Max = TODAY()-LastDays[Last DAys Val]
Sales YTD = 
SUMX(
FILTER(Data;AND(Data[Date]<[Date Max];Data[Date]>= [Date Min]));
Data[Units])

When users change the value of LastDays on a slicer, it will dynamically change the scope :

003.png

 

 

 

View solution in original post

1 REPLY 1
Salonic
Resolver I
Resolver I

Hello,

 

By using a WhatIf parameter, you may let the users choose their parameters dynamically.

 

I created a simple table :

001.png

 

I then created a WhatIf parameter :

LastDays = GENERATESERIES(0; 50; 1)

002.png

 

Inside the data table, I added 3 new measures :

Date Min = DATE(YEAR(TODAY()-LastDays[Last DAys Val]);1;1)
Date Max = TODAY()-LastDays[Last DAys Val]
Sales YTD = 
SUMX(
FILTER(Data;AND(Data[Date]<[Date Max];Data[Date]>= [Date Min]));
Data[Units])

When users change the value of LastDays on a slicer, it will dynamically change the scope :

003.png

 

 

 

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.

Top Solution Authors