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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
bender
New Member

Calculating a running total on a dimensional string value

Hi everyone,

I am working through an issue trying to create a running total based upon a String value in my dimension.  I have a fact table with user records and a AgeSK value that links to a dimension table.  The running total I am attempting to build would give me counts based upon the current period in the dimension, and any records in later periods.  The basic data sets look as follows:

bender_0-1657224811639.png

 

In a previous iteration of this, where I was predetermining the months, I was able to get away with a calculation that utilized the UnboundMonth string value because I created the values with a leading zero so that they would still order properly.  The calculation essentially looked like this (note in that previous iteration the PostSignupAgeSK was stored as a month count, in the above its stored as a day count):

 

TotPostSignupAgeMthRollingQualifiedUsers:=
VAR CurrentMonthNum = SELECTEDVALUE(Dim Table[UnboundMonth])
RETURN
CALCULATE(
[TotQualifiedUsers],
Dim Table[UnboundMonth] >= CurrentMonthNum,
ALL(Dim Table[UnboundMonth])
)

 

This formula won't work for the RetentionPeriod because the string data will not order appropriately to roll the data up sequentially.  What I essentially think needs to happen is I need to bring the AgeSK in to scope to order appropriately, but work from the RetentionPeriod value so that when I visualize the data, that is the label value present.  I found several solutions for doing this when the data points are all in the fact table, I just am unable to properly implement them when using a dimension.  Any and all help would be appreciated.

 

Thank you

1 REPLY 1
amitchandak
Super User
Super User

@bender , I think the above should work for RetentionPeriod , as long as UnboundMonth is sortable.

 

You need a sort column for RetentionPeriod 

 

This should work

CALCULATE(
[TotQualifiedUsers],
filter( ALL(Dim Table[UnboundMonth]) , Dim Table[UnboundMonth] >= max(Dim Table[UnboundMonth] ) ,
)
)

 

 

or

 

CALCULATE(
[TotQualifiedUsers],
filter( ALL(Dim Table[UnboundMonth]) , Dim Table[UnboundMonth] <= max(Dim Table[UnboundMonth] ) ,
)
)

 

How to Create Sort Column and Solve Related Errors:
https://www.youtube.com/watch?v=KK1zu4MBb-c

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.

Top Solution Authors