Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Cumulative Balance Name wise Total

I need result for cumulative balance as doesn't works its giving result as zero for DAX Formula, pls guide

Basically take a highest sales value and cumulative balance as mentioned on below table.

 

Cumulative Balance =

VAR varDate = SELECTEDVALUE('Calendar'[Date])
VAR varProduct = SELECTEDVALUE('File'[Name])
RETURN
CALCULATE(
_Measure[Sales],
'Calendar'[Date] <= varDate,
'File'[Name] = varProduct
)

result :

NameCumulative BalSales Total
Apple5555
Orange9843
Mango13133
Banana15322
Papaya16512

 

  • Hi,

    If it is a cumulative from largest Salest to small try this,

    1st. Create a measure with your sales total (it might be your measure[Sales] value already
      Example:

             Measure = CALCULATE(SUM((File[Sales Total])))
    Then another measure as, 
           Cumulative Sum from Largest =
               VAR CurrentValue = [Measure]  
           RETURN
              CALCULATE(
                                 [Measure],  
                                            FILTER(ALL(YourTable),
                                           [Measure] >= CurrentValue
        )


10 Replies

  • Hi,

    If it is a cumulative from largest Salest to small try this,

    1st. Create a measure with your sales total (it might be your measure[Sales] value already
      Example:

             Measure = CALCULATE(SUM((File[Sales Total])))
    Then another measure as, 
           Cumulative Sum from Largest =
               VAR CurrentValue = [Measure]  
           RETURN
              CALCULATE(
                                 [Measure],  
                                            FILTER(ALL(YourTable),
                                           [Measure] >= CurrentValue
        )


    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi - perfect DAX Formula, I need one more support the cumulative balance should work only v% column have value.

       

      sample dataset:

      NameSales Totalv%CUMbal
      Apple5524%55
      Orange4330%98
      Mango33 131
      Banana2222%153
      Papaya1280%165
      Total165  

       

      output needs :

       

      NameSales Totalv%CUMbal
      Apple5524%55
      Orange4330%98
      Banana2222%120
      Papaya1280%132
      Total165  
  • I didn't see any date data in your result. could you pls provide some sample data?

    • Anonymous's avatar
      Anonymous
      Not applicable
      Name Sales Total
      Apple 55
      Orange 43
      Mango 33
      Banana 22
      Papaya 12

       

      this is dataset and we need to get result of cumulative value as per sales.. see result 

      • ryan_mayu's avatar
        ryan_mayu
        Icon for Super User rankSuper User

        Anonymous 

        if this is your sample data, you need to have an order column.

         

        Column = sumx(FILTER('Table','Table'[order]<=EARLIER('Table'[order])),'Table'[Sales Total])
         
        or 
         
        Measure = sumx(FILTER(all('Table'),'Table'[order]<=max('Table'[order])),'Table'[Sales Total])
         
         
  • v-veshwara-msft's avatar
    v-veshwara-msft
    Icon for Community Support rankCommunity Support

    Hi Anonymous ,
    Thanks for using Microsoft Fabric Community and sharing the detailed requirement.

    Based on your scenario, since you're working with a large dataset (~7GB) and can't create a  'order' column, the best approach is to dynamically calculate the cumulative balance by descending sales, filtered to include only rows where the v% column has a value.

    Please see the following DAX measure:

    Cumulative Balance (With Threshold) = 
    VAR CurrentName = SELECTEDVALUE('Datatable'[Name])
    VAR CurrentSales =
        CALCULATE(
            [Total Sales],
            'Datatable'[Name] = CurrentName
        )
    VAR Threshold = SELECTEDVALUE('Sales Threshold'[Sales Threshold], 0)
    RETURN
    IF(
        CurrentSales > Threshold && NOT ISBLANK(SELECTEDVALUE('Datatable'[v%])),
        CALCULATE(
            [Total Sales],
            FILTER(
                ALL('Datatable'),
                NOT ISBLANK('Datatable'[v%]) &&
                [Total Sales] >= CurrentSales &&
                [Total Sales] > Threshold
            )
        ),
        BLANK()
    )

     

    Output:

     

    If you'd also like to apply filters like Sales > 45, add that condition inside the FILTER as shown below:

    ...
    FILTER(
        ALL('Datatable'),
        NOT ISBLANK('Datatable'[v%]) &&
        CALCULATE(SUM('Datatable'[Sales Total])) >= CurrentSales &&
        'Datatable'[Sales Total] > 45
    )

     

    Hope this helps. Please reach out for further assistance.
    If this post helps, then please consider to Accept as the solution to help the other members find it more quickly and a kudos would be appreciated.

     

    Thank you.

  • v-veshwara-msft's avatar
    v-veshwara-msft
    Icon for Community Support rankCommunity Support

    Hi Anonymous ,

    Just checking in to see if you query is resolved and if any responses were helpful. If so, kindly consider marking the helpful reply as 'Accepted Solution' to help others with similar queries. 

    Otherwise, feel free to reach out for further assistance.

    Thank you.

     

  • v-veshwara-msft's avatar
    v-veshwara-msft
    Icon for Community Support rankCommunity Support

    Hi Anonymous ,

    Following up to see if your query has been resolved. If any of the responses helped, please consider marking the relevant reply as the 'Accepted Solution' to assist others with similar questions.

    If you're still facing issues, feel free to reach out.

    Thank you.

  • v-veshwara-msft's avatar
    v-veshwara-msft
    Icon for Community Support rankCommunity Support

    Hi Anonymous ,

    We’re following up once more regarding your query. If it has been resolved, please mark the helpful reply as the Accepted Solution to assist others facing similar challenges.

    If you still need assistance, please let us know.
    Thank you