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
Niels_T
Post Patron
Post Patron

How to fix this YTD function

I have a YTD function that is forced, meaning that it won't repeat the same number when the YTD function can't find a new value (see image bellow). 

 

The problem here is that as you can see my YTD (Forced) doesn't include the most recent data of April and therefore not really making it YTD as it only adds the data at the end of each month. 

 

image.png

 

Here is my YTD (Forced) function: 

 

YTD Forced = 

var _max = today()
return
if(max('Calendar'[Date])<=_max, calculate(Sum('Credit Memo + Invoice'[Amount]),DATESYTD('Calendar'[Date])), blank())
1 ACCEPTED SOLUTION
v-robertq-msft
Community Support
Community Support

Hi, @Niels_T 

According to your description, I can clearly understand your requirement, you want to get the YTD till today but the data of this month disappeared, right? I think you can try this measure:

This is the test data I created based on your DAX formula:

v-robertq-msft_0-1619166929300.png

YTD Forced =

var _value=

CALCULATE(SUMX(FILTER('Credit Memo + Invoice',[Date]<=TODAY()),[Amount]),DATESYTD('Calendar'[Date]))

return

IF(

    YEAR(MAX('Calendar'[Date]))<YEAR(TODAY()),_value,

    IF(

        MONTH(MAX('Calendar'[Date]))<=MONTH(TODAY()),_value,BLANK()))

 

Then create a table chart to place this measure like this:

v-robertq-msft_1-1619166929308.png

 

And you can get what you want.

You can download my test pbix file below

 

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

3 REPLIES 3
v-robertq-msft
Community Support
Community Support

Hi, @Niels_T 

According to your description, I can clearly understand your requirement, you want to get the YTD till today but the data of this month disappeared, right? I think you can try this measure:

This is the test data I created based on your DAX formula:

v-robertq-msft_0-1619166929300.png

YTD Forced =

var _value=

CALCULATE(SUMX(FILTER('Credit Memo + Invoice',[Date]<=TODAY()),[Amount]),DATESYTD('Calendar'[Date]))

return

IF(

    YEAR(MAX('Calendar'[Date]))<YEAR(TODAY()),_value,

    IF(

        MONTH(MAX('Calendar'[Date]))<=MONTH(TODAY()),_value,BLANK()))

 

Then create a table chart to place this measure like this:

v-robertq-msft_1-1619166929308.png

 

And you can get what you want.

You can download my test pbix file below

 

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

HarishKM
Impactful Individual
Impactful Individual

@Niels_T  Hey Mate try these Dax

Sales of 2 Product = SUM(financials[COGS]) + SUM(financials[ Sales])
YTD of 2 product = CALCULATE([Sales of 2 Product],DATESYTD(financials[Date]))
LY YTD =
VAR _LY =
CALCULATE ( [Sales of 2 Product], SAMEPERIODLASTYEAR ( financials[Date] ) )
RETURN
CALCULATE ( _LY, DATESYTD ( financials[Date] ) )

 

HarishKM_0-1618990932433.png

 

Unfortunately this is not what I am looking for. The first measure is a standard YTD where the value gets repeated. 

 

The LY YTD gives me also very different results and also does not stop till this date with showing the values.

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.