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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
lancea
Helper I
Helper I

Calculate an Estimated YTD Total with a static Measure

Considering I have the following table:

 

DateSalesYTD SalesStatic Estimate for Sales
Jan-202110001000500
Feb-202120003000500
Mar-202110004000500
Apr-202115005500500
May-202115007000500
Jun-2021 7500500
Jul-2021 8000500
Aug-2021 8500500
Sep-2021 9000500

 

How do I go about creating a measure or calculated column for the YTD Sales column? The formula is YTD, but if there is no value for the current month, then add the Static Estimate value instead (to show something like a forecast).

1 ACCEPTED SOLUTION

Hi, @lancea ;

You could try to delete the .date in the picture, if it doesn’t work, you can just copy my code and change the key field

v-yalanwu-msft_0-1623405116483.png

The final output is shown below: 

v-yalanwu-msft_1-1623405214066.png

Best Regards,
Community Support Team_ Yalan Wu
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

4 REPLIES 4
v-yalanwu-msft
Community Support
Community Support

Hi, @lancea ;

You could create a measure by the following formula:

YTD Sales1 =
VAR _sale =
    CALCULATE ( SUM ( [Sales] ), DATESYTD ( 'Table'[Date], "12/31" ) )
VAR _static =
    CALCULATE (
        SUM ( [Static Estimate for Sales] ),
        DATESYTD ( 'Table'[Date], "12/31" ),
        FILTER ( ALL ( 'Table' ), [Sales] = BLANK () )
    )
RETURN
    IF ( MAX ( [Sales] ) = BLANK (), _static + _sale, _sale )

Or you could create a column:

YTD Sales2 =
VAR _sales =
    CALCULATE (
        SUM ( [Sales] ),
        DATESYTD ( 'Table'[Date], "12/31" ),
        ALL ( 'Table' )
    )
VAR _static =
    CALCULATE (
        SUM ( [Static Estimate for Sales] ),
        DATESYTD ( 'Table'[Date], "12/31" ),
        FILTER ( ALL ( 'Table' ), [Sales] = BLANK () )
    )
RETURN
    IF ( [Sales] = BLANK (), _sales + _static, _sales )

The final output is shown below:  

 v-yalanwu-msft_0-1623376444395.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello,

 

Unfortunately, I am getting the incorrect result as shown below:

 

YTD Sales1 =
VAR _sale =
CALCULATE ( SUM ( [Sales] ), DATESYTD ( Sheet1[Date Description].[Date], "12/31" ) )
VAR _static =
CALCULATE (
SUM ( Sheet1[static] ),
DATESYTD ( Sheet1[Date Description].[Date], "12/31" ),
FILTER ( ALL ( Sheet1 ), [Sales] = BLANK () )
)
RETURN
IF ( SUM ( [Sales] ) = 0, _static + _sale, _sale )

 

lancea_0-1623398562030.png

 

Please note that static column in my case is a CalculatedColumn with a flat value of 75 (static = 75). And here is my dataset (for some reason, it won't allow me to post table):

 

lancea_0-1623399241664.png

Can you please let me know what I am doing wrong?

Hi, @lancea ;

You could try to delete the .date in the picture, if it doesn’t work, you can just copy my code and change the key field

v-yalanwu-msft_0-1623405116483.png

The final output is shown below: 

v-yalanwu-msft_1-1623405214066.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

amitchandak
Super User
Super User

@lancea , Try a measure like this with help from date table

 

YTD Sales = CALCULATE(SUMX(values(Date[Month Year]) , calculate(if isblank(sum(Sales[Sales])) , sum(Table[Static Estimate]), sum(sales[Sales]))),DATESYTD('Date'[Date],"12/31"))

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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