Forum Discussion
Advanced Sum between Dates
- 4 years ago
Hi Contezini
Here is a sample file with the solution https://www.dropbox.com/t/BFyYg068Dfa9YNbe
We have two issue to solve here.The first one we have define which start belongs to which end as there is no stage or ranking column that related each start to its relevant end.
The 2nd issue is generate only the relevant rows in between each start and stop.
Here is the data model with inactive or no relationship with the date table.
The first issue can be solved by creating the following calculated column
Ranking = RANKX ( CALCULATETABLE ( 'Site Log', ALLEXCEPT ( 'Site Log', 'Site Log'[Site_ID],'Site Log'[Log Change] ) ), 'Site Log'[Date],, ASC )The measure that generates the relevant rows with the relevant site size
Filter Measure = VAR CurrentDate = MAX ( 'Date'[Date] ) VAR T1 = ADDCOLUMNS ( SUMMARIZE ( 'Site Log', 'Site Log'[Site_ID],'Site Log'[Ranking],'Site Sizes'[Site_Size] ), "@Start", CALCULATE ( MAX ( 'Site Log'[Date] ), 'Site Log'[Log Change] = "Started" ), "@End", COALESCE ( CALCULATE ( MAX ( 'Site Log'[Date] ), 'Site Log'[Log Change] = "Ended" ), TODAY ( ) ) ) VAR T2 = GENERATE ( T1, VAR StartDate = [@Start] VAR EndDate = [@End] RETURN CALENDAR ( StartDate, EndDate ) ) VAR T3 = FILTER ( T2, [@Start] <= CurrentDate && [@End] >= CurrentDate ) RETURN MAXX ( T3, [Site_Size] )
Contezini , merge size and log tables
or create a measure
M1 = sumx(relatedtable(Size), Size(Size)
Then try a measure like
calculate( [M1], filter(all(Date), Date[Date] <= Max(Date[Date])), filter(Log, Log[Log Change] ="Started"))
- calculate( [M1], filter(all(Date), Date[Date] <= Max(Date[Date])), filter(Log, Log[Log Change] ="Ended"))