Forum Discussion

datadax123's avatar
datadax123
Regular Visitor
2 years ago

Cumulative Sum - 2 conditions

Hey everyone !

 

I have done many tests here but can't find any solution, any help is appreciated.

 

I have a complex dashboard but I simplified it here in order to focus on the issue :

 

I have three tables : Validity_List, Possibility_List and Sales_Start. Here are some extracts of theses tables :

 

Validity_List : All sales of product/color per period of sales (ID is the combination of Color/Product/Sales start/Sales end)

 

ColorProductSales startSales EndQuantityID
AP10086A_P1_0_0
AP1103A_P1_1_0
AP1111A_P1_1_1
BP32002B_P32_0_0
CP32005C_P32_0_0
DP2002D_P2_0_0
DP212111D_P2_12_11
DP212101D_P2_12_10
DP241342D_P2_41_34
DP320063D_P32_0_0

 

Possibility_List: All combination of color/product/sales start and sales end possible. It also includes for other purposes combination that do not exist in validity_list. (ID is the combination of Color/Product/Sales start/Sales end)

 

ColorProductSales StartSales EndID
AP10-1A_P1_0_-1
AP100A_P1_0_0
AP11-1A_P1_1_-1
AP110A_P1_1_0
AP111A_P1_1_1
AP12-1A_P1_2_-1
AP13-1A_P1_3_-1
BP10-1B_P1_0_-1
BP320-1B_P32_0_-1
BP3200B_P32_0_0
CP3200C_P32_0_0
DP200D_P2_0_0
DP21211D_P2_12_11
DP21210D_P2_12_10
DP24134D_P2_41_34
DP3200D_P32_0_0

 

Sales_Start: All possible sales starts (

 

Sales Start
0
1
2
3
4
5
6
7
8
9
10
11
12
13
20
27
34
41

 

The tables are organised this way : 

 

 

What I need is a measure that for every value of [Sales start]Sales start would dislay the quantity sold from the validity tables where at the same time:
[Sales start]Sales start <= [Validity_List]Sales start

[Sales start]Sales start > [Validity_List]Sales End

 

Thank you !

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi datadax123 ,

    I would appreciate it if you could give me the expected results, thank you.

    Best Regards,

    Xianda Tang

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

    • datadax123's avatar
      datadax123
      Regular Visitor

      Hey Anonymous ,

      In this example it would be : 

      Sales StartQuantity
      0 
      13
      2 
      3 
      4 
      5 
      6 
      7 
      8 
      9 
      10 
      111
      122
      13 
      20 
      27 
      34 
      412



      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi datadax123 ,

        Below is my table1:

        Below is my table2:

        Below is my table3:

        The following DAX might work for you:

        Measure = 
           var _sale = SELECTEDVALUE(Sales_Start[Sales Start])
           var _val_start = SELECTEDVALUE(Validity_List[Sales start])
           var _val_End = SELECTEDVALUE(Validity_List[Sales End])
           var _Quan = SELECTEDVALUE(Validity_List[Quantity])
           RETURN
           IF(_sale <= _val_start && _sale > _val_End , _Quan , BLANK())

        The final output is shown in the following figure:

        Best Regards,

        Xianda Tang

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