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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
matt_g_tribal
Frequent Visitor

cumulative totals to date by client

Hi all, I'm having trouble writing some cumulative totals because I want the formula to work with both variable dates and variable customers. I'm trying to calculate sales to date, where the base formula looks like this:

 

Balance owed = 
calculate(
sum(FactTransactions[Balance change]),
filter(
ALLSELECTED(FactTransactions),
FactTransactions[month and year] <= max(FactTransactions[month and year]),
)
)

 

My problem comes because I need to show the results in other locations, where my context is the customer instead of the date. I'm trying to extend the formula, which currently looks like this:

 


balance owed 2 = 
var maxDate = max(FactTransactions[month and year])
var customer = FactTransactions[customer key]
return
calculate(
    [Balance change],
    FactTransactions[month and year] <= maxDate && FactTransactions[customer key] = customer,   
    allselected(FactTransactions)
)

This doesn't work becase my variable "Customer" is trying to refer to the current context and the syntax is clearly wrong. I've included it just to demonstrate what I'm trying to do, which is allow all historic dates but only a single client IF the context is single client

 

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

Hi @matt_g_tribal ,

 

According to your description, my understanding is that you want to compute the cumulative total by [customer key] and [month and year]   If anything is misunderstood, please tell me.

 

Would you please try to use the following dax code to create the calculated column:

 

Balance owed1 =

IF (

    HASONEFILTER ( FactTransactions[customer key] ),

    CALCULATE (

        SUM ( FactTransactions[Balance change] ),

        FILTER (

            ALLSELECTED ( FactTransactions ),

            FactTransactions[customer key] <= MAX ( FactTransactions[customer key] )

        )

    ),

    CALCULATE (

        SUM ( FactTransactions[Balance change] ),

        FILTER (

            ALLSELECTED ( FactTransactions ),

            FactTransactions[month and year] <= MAX ( FactTransactions[month and year] )

        )

    )

)

 

Untitled picture4.png

 

Please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/ESIVHFYFMiBBm_WhRz...

 

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

 

Best Regards,

Dedmon Dai

 

View solution in original post

3 REPLIES 3
v-deddai1-msft
Community Support
Community Support

Hi @matt_g_tribal ,

 

According to your description, my understanding is that you want to compute the cumulative total by [customer key] and [month and year]   If anything is misunderstood, please tell me.

 

Would you please try to use the following dax code to create the calculated column:

 

Balance owed1 =

IF (

    HASONEFILTER ( FactTransactions[customer key] ),

    CALCULATE (

        SUM ( FactTransactions[Balance change] ),

        FILTER (

            ALLSELECTED ( FactTransactions ),

            FactTransactions[customer key] <= MAX ( FactTransactions[customer key] )

        )

    ),

    CALCULATE (

        SUM ( FactTransactions[Balance change] ),

        FILTER (

            ALLSELECTED ( FactTransactions ),

            FactTransactions[month and year] <= MAX ( FactTransactions[month and year] )

        )

    )

)

 

Untitled picture4.png

 

Please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/ESIVHFYFMiBBm_WhRz...

 

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

 

Best Regards,

Dedmon Dai

 

amitchandak
Super User
Super User

@matt_g_tribal , Under quick formula you have an option for running total. That will give you the required measure.

 

Greg_Deckler
Super User
Super User

Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.