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
MAVIE
Helper I
Helper I

Cumulative Total with Dates Sliced by Separate Table

Hi All,

I'm trying to build a dynamic cumulative totals measure, where the date dimension is able to be sliced by the data ranges from an iterations dimension.  The measure the I'm working off of is the following, which lets me slice the dates to get the correct results: 

CALCULATE (
    SUM ( FactTimeRegistrations[Hours] ),
    FILTER ( ALLSELECTED ( DimDate[Date] ) , DimDate[Date] <= MAX ( DimDate[Date] ) )
)

 However, I want to add an additional filter to be able to slice the date based off of the date range from a given iteration, but I have been unsuccessful so far. 
The three tables that the meassure would be using are these: Picture1.png
Any help would be greatly appreciated!

1 ACCEPTED SOLUTION

HI @MAVIE 
Please try

Hours RT =
VAR T1 =
    FILTER ( ALLSELECTED ( DimDate[Date] ), DimDate[Date] <= MAX ( DimDate[Date] ) )
VAR StartDate =
    MAXX ( FactTimeRegistrations, RELATED ( DimIterations[StartDate] ) )
VAR EndDate =
    MAXX ( FactTimeRegistrations, RELATED ( DimIterations[EndDate] ) )
VAR T2 =
    CALENDAR ( StartDate, EndDate )
RETURN
    CALCULATE ( SUM ( FactTimeRegistrations[Hours] ), INTERSECT ( T1, T2 ) )

View solution in original post

8 REPLIES 8
tamerj1
Super User
Super User

@MAVIE 
First create realtionship as follows

1.png

Then use

Hours RT =
VAR T1 =
    FILTER ( ALLSELECTED ( DimDate[Date] ), DimDate[Date] <= MAX ( DimDate[Date] ) )
VAR T2 =
    CALENDAR (
        RELATED ( DimIterations[StartDate] ),
        RELATED ( DimIterations[EndDate] )
    )
RETURN
    CALCULATE ( SUM ( FactTimeRegistrations[Hours] ), INTERSECT ( T1, T2 ) )

Hi @tamerj1 

I should have clarified the relationship. Iterations if connected to TimeRegistrations in this manner: 

MAVIE_2-1652773778829.png

 


Also the chart that I'm creating looks as such, which has been sliced on the desired iteration. The issue then is that that have data point from before the iteration which should not be included in the calculation.
Picture3.png

 

Hi @MAVIE 
The same code above shall remain applicable. Please check and let me know which results you get. Thank you

Using that measure I get the following error

MAVIE_0-1652777520480.png

 

HI @MAVIE 
Please try

Hours RT =
VAR T1 =
    FILTER ( ALLSELECTED ( DimDate[Date] ), DimDate[Date] <= MAX ( DimDate[Date] ) )
VAR StartDate =
    MAXX ( FactTimeRegistrations, RELATED ( DimIterations[StartDate] ) )
VAR EndDate =
    MAXX ( FactTimeRegistrations, RELATED ( DimIterations[EndDate] ) )
VAR T2 =
    CALENDAR ( StartDate, EndDate )
RETURN
    CALCULATE ( SUM ( FactTimeRegistrations[Hours] ), INTERSECT ( T1, T2 ) )

Hi @tamerj1 

This measure seems to work as intended. If anything else goes wrong, I'll try to share some test data with you. 

Thank you very much for your help!

Hi @MAVIE 
Please provide sample data to work with

tamerj1
Super User
Super User

Hi @MAVIE 

how does your report look like?

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