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
joemillson
Frequent Visitor

Cumulative total - stopping after last date not working with hierarchy

Hi - i've created a measure as shown here to create a cumulative sum up to the last sales date, then to give a blank after that date:

 

Cml Actual Invoices =
VAR LastSalesDate = CALCULATE(LASTDATE(f_scoro_SalesInvoicesActual[Date Invoice]),ALL())
RETURN
IF(
SELECTEDVALUE(d_time_Dates[Date]) > LastSalesDate, BLANK(),
CALCULATE([Sum of Actual Invoices],
FILTER(ALLSELECTED(d_time_Dates),d_time_Dates[Date] <= MAX(d_time_Dates[Date]))))
 
It shows correctly if my visual is operating at the single date level:
joemillson_0-1624792977434.png

However I need to be able to move up / down a date hierarchy and for the measure to work, which is currently is not doing, as shown below if i move up to Month granularity, the meaure no longer returns a blank after the last sale date, and repeats the cumulative total for months beyond the last date:

 

joemillson_1-1624793092067.png

I think I understand why, becuase in my measure I'm calculating based on the full date key and not the month, however I don't know the solution. Any help would be appreciated.

 

Thank you,

Joe

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@joemillson , This seems fine and should work in a hierarchy. Just make sure that all these Fiscal Year, Qtr, and Month are coming from date table, d_time_Dates and that is marked as date table

 

Try this too

Cml Actual Invoices =
VAR LastSalesDate = maxx(ALL(f_scoro_SalesInvoicesActual),f_scoro_SalesInvoicesActual[Date Invoice])
RETURN
IF(
max(d_time_Dates[Date]) > LastSalesDate, BLANK(),
CALCULATE([Sum of Actual Invoices],
FILTER(ALLSELECTED(d_time_Dates),d_time_Dates[Date] <= MAX(d_time_Dates[Date]))))

 

or

 

 

Cml Actual Invoices =
VAR LastSalesDate = maxx(ALL(f_scoro_SalesInvoicesActual),f_scoro_SalesInvoicesActual[Date Invoice])
RETURN
CALCULATE([Sum of Actual Invoices],
FILTER(ALLSELECTED(d_time_Dates),d_time_Dates[Date] <= MAX(d_time_Dates[Date]) && (d_time_Dates[Date]) <= LastSalesDate))

View solution in original post

3 REPLIES 3
JoaoEccel
Regular Visitor

The first option works just as I needed. Thank you so much!

amitchandak
Super User
Super User

@joemillson , This seems fine and should work in a hierarchy. Just make sure that all these Fiscal Year, Qtr, and Month are coming from date table, d_time_Dates and that is marked as date table

 

Try this too

Cml Actual Invoices =
VAR LastSalesDate = maxx(ALL(f_scoro_SalesInvoicesActual),f_scoro_SalesInvoicesActual[Date Invoice])
RETURN
IF(
max(d_time_Dates[Date]) > LastSalesDate, BLANK(),
CALCULATE([Sum of Actual Invoices],
FILTER(ALLSELECTED(d_time_Dates),d_time_Dates[Date] <= MAX(d_time_Dates[Date]))))

 

or

 

 

Cml Actual Invoices =
VAR LastSalesDate = maxx(ALL(f_scoro_SalesInvoicesActual),f_scoro_SalesInvoicesActual[Date Invoice])
RETURN
CALCULATE([Sum of Actual Invoices],
FILTER(ALLSELECTED(d_time_Dates),d_time_Dates[Date] <= MAX(d_time_Dates[Date]) && (d_time_Dates[Date]) <= LastSalesDate))

Thanks very much - the first alternative works perfectly.

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