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

Win a FREE 3 Day Ticket to FabCon Vienna. Apply now

Reply
hilmer101
New Member

Limited YTD line using Month Number

Hi,

 

I have an YTD line in a graph. I want it to be limited to February 2021, as I only have data until that point of time.

 

My DAX looks like this:

YTD 2021 Total Cost = CALCULATE (
sum('V-LOG Market KPI Overview'[Total Cost]) / SUM('V-LOG Market KPI Overview'[Sold M3]),
Filter(
ALL ( 'Fiscal Calendar' ),
'Fiscal Calendar'[Year] = 2021 &&
'Fiscal Calendar'[Month Number] <= MAX ( 'Fiscal Calendar'[Month Number] )
)

)

 

hilmer101_0-1615283064335.png

 

Thank you.

 

Best Regards,

Daniel

 

1 ACCEPTED SOLUTION
jameszhang0805
Resolver IV
Resolver IV

@hilmer101 Please try below solution 
Create a measure: 
This measure is used to determine whether the currently selected date is greater than the maximum date in the fact table, that is, whether the currently selected date is in the future.

ShowValueForDates = 
VAR _LastDateWithData =   -- calculate the maximum date in your fact table 
    CALCULATE (
        MAX ( 'MF_MB51'[Posting Date] ),
        REMOVEFILTERS ()
    )
VAR _FirstDateVisible =   
    MIN ( 'MD_Date'[Date] )
VAR _Result =
    _FirstDateVisible <= _LastDateWithData
RETURN
    _Result

 Then Put the measure in your YTD calculation.

MVTYTD.DYN = 
IF( 
    [ShowValueForDates] ,
        CALCULATE( [MVTQTY.DYN] , 
            DATESYTD( 'MD_Date'[Date] ) 
        )
)



View solution in original post

1 REPLY 1
jameszhang0805
Resolver IV
Resolver IV

@hilmer101 Please try below solution 
Create a measure: 
This measure is used to determine whether the currently selected date is greater than the maximum date in the fact table, that is, whether the currently selected date is in the future.

ShowValueForDates = 
VAR _LastDateWithData =   -- calculate the maximum date in your fact table 
    CALCULATE (
        MAX ( 'MF_MB51'[Posting Date] ),
        REMOVEFILTERS ()
    )
VAR _FirstDateVisible =   
    MIN ( 'MD_Date'[Date] )
VAR _Result =
    _FirstDateVisible <= _LastDateWithData
RETURN
    _Result

 Then Put the measure in your YTD calculation.

MVTYTD.DYN = 
IF( 
    [ShowValueForDates] ,
        CALCULATE( [MVTQTY.DYN] , 
            DATESYTD( 'MD_Date'[Date] ) 
        )
)



Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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