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
Anonymous
Not applicable

Cumulative Sum including Nulls

Hi Gurus, 

I am calculating cumulative sum for total cases worked upon by employees. However, if in a month an employee doesn't have any cases because of the join with dim_Calendar I am getting Nulls and hence the values post that are appearing as Nulls. 

I have tried If condition for the total column to use 0 in place of but it didn't help/. 

 

I tried modifying the creating a measure to replace the original column by 0 in case of NULLs but the function didn't give me expeicted results. 

I can't replace Nulls with 0s in power query as there are no rows in original source for these users since they didn't complete any cases. 

 

Thanks in advance !

 

Here is the original formula and the modified formulas I have tried so far to no use :

 

Cumulative cases Last month = CALCULATE (SUM(Monthlypayments[Total cases]),filter(ALLSELECTED( Calendar_dim), Calendar_dim[Date]<=maxx(Calendar_dim,dateadd(Calendar_dim[Date],-1,month))))+0

 

tried :

Cumulative Specialities LastMonthNull = VAR transmaxdate =
CALCULATE ( Max(Calendar_dim[Date]), ALL ( 'Calendar_dim' ) )
VAR spec =
TOTALYTD ( SUM ( Monthlypayments[Total cases] ), Calendar_dim[Date])
return
IF ( MIN ( 'Calendar_dim'[Date] ) <= transmaxdate, spec ,0 )

 

another option : 

Cumulative Specialities LastMonthNull = CALCULATE (If(ISBLANK(Sum(Monthlypayments[Total cases])),0,sum(Monthlypayments[Total cases])),filter(ALL( Calendar_dim), Calendar_dim[Date]<= MAXX(Calendar_dim,DATEADD(Calendar_dim[Date],-1,MONTH))))
 
Here is the sample dataset :
MonthUserCases this monthCumuluative Output I get(cumulative last month)Output I want
JanA10  
FebA201010
Mar A403030
AprA  70
MayA  70
JanB15  
FebB301515
Mar B254545
AprB207070
MayB  90
     
 
1 ACCEPTED SOLUTION
ERD
Super User
Super User

Hi @Anonymous ,

I don't know all the prerequisites and how your raw data looks like, but assuming you have a proper Calendar table ("Date" in my example) connected to your Data table by Date column:

Measure 1:

 

CasesAmt = COALESCE(SUM(ASGMT[Cases]),0)

 

Measure 2:

 

CasesYTD = CALCULATE([CasesAmt], DATESYTD('Date'[Date]))

 

ERD_2-1623678523324.png

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

 

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

4 REPLIES 4
ERD
Super User
Super User

Hi @Anonymous ,

I don't know all the prerequisites and how your raw data looks like, but assuming you have a proper Calendar table ("Date" in my example) connected to your Data table by Date column:

Measure 1:

 

CasesAmt = COALESCE(SUM(ASGMT[Cases]),0)

 

Measure 2:

 

CasesYTD = CALCULATE([CasesAmt], DATESYTD('Date'[Date]))

 

ERD_2-1623678523324.png

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

 

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Anonymous
Not applicable

Thank you ERD! Looks like I had an issue with my Data modelling. I had selected both as cross filtering direction which was causing troubles. As soon as I corrected the cross filtering direction, my previous formula and the one suggested by you started to work 🙂 Thanks heaps for your help 🙂

CNENFRNL
Community Champion
Community Champion

Use a disconnected table to for Year-Month row,

Screenshot 2021-06-14 132058.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Anonymous
Not applicable

@CNENFRNL - Thanks for your reply! I did implemented the same thing and created the disjoined table and the ytd measure as  below but it just gives me the calculations for that month rather than cumulative numbers. I still however have the calendar dim joined ? Could that be the reason ?

Cumulative cases =
VAR __ym = MAX ( YrMMM[ym] )
VAR __ym_max = CALCULATE ( MAX ( Monthlypayments[Yearmonth] ), ALLSELECTED( Monthlypayments) )
RETURN
IF ( MAX( YrMMM[ym]) <= __ym_max,
CALCULATE ( SUM ( Monthlypayments[Total case] ),
CALCULATETABLE ( DATESYTD ( Monthlypayments[datecompleted]), Monthlypayments[Yearmonth] <= __ym )
) ) 
Datecompleted column is defaulted to the 1st day of the month along with the cases completed for that month in the summary table I am using. Thanks for your help with this!

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