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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Pall
Regular Visitor

How to calculate Cumulative Values when there are missing dates ?

Hi Sir,
Using line graph to display cumulative values
using below DAX. to handle missing dates and also have slicers to filter required sub_products.
**bleep** Mat Sold  =
Var _cum =CALCULATE(SUM ( Table Name [Sales] ),
'Date Table'[Date] <= MAX('Date Table'[Date]))
Return
IF(ISBLANK(SUM ( Table Name [Sales] )),_cum+0,_cum)
Example :
Date Prod Sub_Prod Sales
1/1/2022 sam sam_2 10
1/2/2022 Ram Ram_1 2
1/3/2022 sam sam_2 4
1/4/2022 Sam Sam_1 0
1/5/2022 sam sam_2 8
1/6/2022 Ram Ram_2 3
1/7/2022 Ram Ram_1 5
1/8/2022 Tem Tem_1 11
1/9/2022 Sam Sam_1 0

As you see in below table .If filter by Sub_PRod -> the graph line is going down at missing dates. Actually the graph must should have straight line at missing dates

Date Prod Sub_Prod Sales
1/1/2022 sam sam_2 10
1/3/2022 sam sam_2 4
1/4/2022 Sam Sam_1 0
1/5/2022 sam sam_2 8
1/9/2022 Sam Sam_1 0

Please help me for the solution to handle for missing dates values
Thanks in advance

 

 

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Thanks for the reply from @Ashish_Mathur and @Uzi2019 , please allow me to provide another insight:

Hi  @Pall ,

 

Here are the steps you can follow:

1. Create calculated table.

Table 2 =
DISTINCT('Table'[Sub_Prod])

vyangliumsft_0-1714541016882.png

2. Create measure.

Sales_Measure =
var _select=SELECTCOLUMNS('Table 2',"test",'Table 2'[Sub_Prod])
return
IF(
    MAX('Table'[Sub_Prod]) in _select,SUM('Table'[Sales]),0)

If you want to do all accumulation based on the slicer selection, you can use the following measure

Cumulative Sales =
SUMX(
    FILTER(ALL('Table'),
    'Table'[Date]<=MAX('Table'[Date])),[Sales_Measure])

If you want to do year and month grouping accumulation based on the slicer selection, you can use the following measure

Cumulative Sales Group =
SUMX(
    FILTER(ALL('Table'),    YEAR('Table'[Date])=YEAR(MAX('Table'[Date]))&&MONTH('Table'[Date])=MONTH(MAX('Table'[Date]))&&'Table'[Date]<=MAX('Table'[Date])),[Sales_Measure])

3. Result:

vyangliumsft_1-1714541016890.png

 

 

Best Regards,

Liu Yang

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

View solution in original post

6 REPLIES 6
v-yangliu-msft
Community Support
Community Support

Thanks for the reply from @Ashish_Mathur and @Uzi2019 , please allow me to provide another insight:

Hi  @Pall ,

 

Here are the steps you can follow:

1. Create calculated table.

Table 2 =
DISTINCT('Table'[Sub_Prod])

vyangliumsft_0-1714541016882.png

2. Create measure.

Sales_Measure =
var _select=SELECTCOLUMNS('Table 2',"test",'Table 2'[Sub_Prod])
return
IF(
    MAX('Table'[Sub_Prod]) in _select,SUM('Table'[Sales]),0)

If you want to do all accumulation based on the slicer selection, you can use the following measure

Cumulative Sales =
SUMX(
    FILTER(ALL('Table'),
    'Table'[Date]<=MAX('Table'[Date])),[Sales_Measure])

If you want to do year and month grouping accumulation based on the slicer selection, you can use the following measure

Cumulative Sales Group =
SUMX(
    FILTER(ALL('Table'),    YEAR('Table'[Date])=YEAR(MAX('Table'[Date]))&&MONTH('Table'[Date])=MONTH(MAX('Table'[Date]))&&'Table'[Date]<=MAX('Table'[Date])),[Sales_Measure])

3. Result:

vyangliumsft_1-1714541016890.png

 

 

Best Regards,

Liu Yang

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

Ashish_Mathur
Super User
Super User

Hi,

Not sure whether those 2 tables are raw data tables or not.  Just share 2 tables - input and result.  Also, specify the filter condition for generating the result table.  Share data in a format that can be pasted in an MS Excel file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

For suppose this is actual table with T_Sales

DateProdSub_ProdSales
1/1/2022samsam_210
1/2/2022RamRam_12
1/3/2022samsam_24
1/4/2022SamSam_10
1/5/2022samsam_28
1/6/2022RamRam_23
1/7/2022RamRam_15
1/8/2022TemTem_111
1/9/2022SamSam_10

Need to calculate cumulative Sales 
and Result should 

DateProdSub_ProdSalesCumulative Sales
1/1/2022samsam_21010
1/2/2022RamRam_1212
1/3/2022samsam_2416
1/4/2022SamSam_1016
1/5/2022samsam_2824
1/6/2022RamRam_2327
1/7/2022RamRam_1532
1/8/2022TemTem_11143
1/9/2022SamSam_1043

 
And filter data by using Slicer Sub_Prod -> Sam_1 and Sam_2 
 Result should be 

DateProdSub_ProdSalesCumulative Sales
1/1/2022samsam_21010
1/2/2022RamRam_1010
1/3/2022samsam_2414
1/4/2022SamSam_1014
1/5/2022samsam_2822
1/6/2022RamRam_2022
1/7/2022RamRam_1022
1/8/2022TemTem_1022
1/9/2022SamSam_1022

 

If i use same "cumulative sales " line graph the line should have all the dates with +0 vlaues 

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1714477078821.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks for the quick respond. but actually in the above case also, there is missing dates with Feb. 

Uzi2019
Super User
Super User

Hi @Pall 
Try below dax

Cumulative = 
  VAR __Date = MAX('DIM_Date'[Date])
  VAR __Table = FILTER(ALL('Table'), [Date] <= __Date)
  VAR __Result = SUMX( __Table, [Column])
RETURN
  __Result

 

I hope i would resolved your issue!

 

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.