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
snph1777
Helper V
Helper V

Microsoft Power BI DAX - Running (Moving) Total within groups and sub-groups, WITHOUT Date dimension

I have an interesting situation in which I need to develop running (moving) totals without Time Intelligence.

 

I do not have a special Date dimension table in my Power BI data model.

 

See the source table below:

 

ts1.GIF

 

I have a measure:

 

TotalLaptops = SUM(TableSource[Laptops])

 

I need to develop a running total, which is only partially date related. I have DeliveryDates that spread across years. I need to get the cumulative sum taking each of the 3 groups to account without worrying about how the dates spread across months, or even years. However, the order of the dates is important for the cumulative total (obviously).

 

I need a new measure called [LaptopRunningTotal].

 

ts2.GIF

 

Any idea on how to develop the new measure?

 

 

 

LaptopRunningTotal = CALCULATE (

                                 [TotalLaptops],

                                  FILTER (

                                          ALL(TableSource),

                                          TableSource[DeliveryDate] <= MAX(TableSource[DeliveryDate])
                                                               &&
                                          TableSource[Group1] = MAX(TableSource[Group1])
                                                               &&
                                          TableSource[Group2] = MAX(TableSource[Group2])
                                                               &&
                                          TableSource[Group3] = MAX(TableSource[Group3])

                                        )

                                )

 

 

 

Is this one above okay ? Am not sure whether the above is fool-proof, please let me know.

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@snph1777 , This one seem fine. If you want filters to work use allselected

 

LaptopRunningTotal = CALCULATE (
[TotalLaptops],
FILTER (
allselected (TableSource),
TableSource[DeliveryDate] <= MAX(TableSource[DeliveryDate])
&&
TableSource[Group1] = MAX(TableSource[Group1])
&&
TableSource[Group2] = MAX(TableSource[Group2])
&&
TableSource[Group3] = MAX(TableSource[Group3])
)
)

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@snph1777 , This one seem fine. If you want filters to work use allselected

 

LaptopRunningTotal = CALCULATE (
[TotalLaptops],
FILTER (
allselected (TableSource),
TableSource[DeliveryDate] <= MAX(TableSource[DeliveryDate])
&&
TableSource[Group1] = MAX(TableSource[Group1])
&&
TableSource[Group2] = MAX(TableSource[Group2])
&&
TableSource[Group3] = MAX(TableSource[Group3])
)
)

thanks @amitchandak 

 

I will get back after updating the code

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.